Private Properties Exposed
For our Components project we are ofcourse writing unit tests (with PHPUnit ). Sometimes you would want to test whether a private property contains the correct data, and of course with the normal visibility rules you can't access those from your unit test. There is an interesting trick for this, which I'll share here:
<?php
class foo {
private $bar = 42;
}
$obj = new foo;
$propname="\0foo\0bar";
$a = (array) $obj;
echo $a[$propname];
?>
Comments
$f->{"0Foo0id"} (for private members) and $f->{"0*0name"} (for protected ones) used to work. Too bad someone added a "Cannot access property started with '0'" fatal error to the Zend Engine in the meantime, making necessary the array-cast hack presented here...
I'd rather have ReflectionProperty->setAccessible(TRUE) like (insert other programming language here):)
Life Line
Whoop! FOSDEM travel and hotel booked. See you in Brussels at the end of January?
I walked 3.0km in 33m38s
I walked 0.6km in 11m26s
I walked 6.5km in 1h17m46s
Updated a cafe
Updated a museum
I walked 1.1km in 12m41s
Updated a bench and a waste_basket
Updated a bench
Updated a bench
Updated a bench
I walked 8.0km in 1h44m20s
I walked 7.9km in 1h32m02s
I've just finished reading "Snow Crash" by Neal Stephenson. I found this a fun and excellent read.
I walked 14.7km in 3h51m29s
I walked 0.8km in 8m42s
I walked 6.0km in 1h19m04s
I walked 1.8km in 49m15s
Updated a restaurant
Updated a restaurant
Updated a restaurant
Updated a restaurant
Updated a brewery
Updated a restaurant
Updated a restaurant


Shortlink
This article has a short URL available: https://drck.me/ppe-46g