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
I walked 2.8km in 18m39s
I've just finished reading The Things We Make by Bill Hammack.
A curious introduction into the world of the engineering method. How it's different from pure science and with the end product of serving mankind in mind.
Updated a restaurant
Updated 2 restaurants; Confirmed a bakery shop
I walked 4.1km in 48m53s
Updated a restaurant
Updated a bar
I walked 8.9km in 4h29m34s
Updated a restaurant
The holiday took a different turn, and view, after last night's sprinkle of tear gas in Nice's air.
Updated a restaurant; Confirmed a toilet
Updated a hotel and a bar
I walked 5.2km in 57m08s
Updated a bar
Updated a restaurant, a museum, and a ticket shop
Updated a cafe
I walked 6.2km in 3h33m10s
An evening out in Nice turned out a little bit more exciting than planned, with a little spot of rioting and bottles thrown at police. Sidestreets FTW.
Updated a restaurant; Confirmed a restaurant
Created a hairdresser shop and a bag shop; Updated a restaurant
Confirmed 2 convenience shops, a gift shop, and a photo shop
Updated a bar
Created a gift shop; Updated a restaurant
Created a clinic
Updated a cafe



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