var_export and classes
Today I stumbled upon an old problem while using var_export() on an array with objects. var_exports()'s description is " Outputs or returns a parsable string representation of a variable ", but it didn't work to well in this case:
array (
0 =>
class ezcTranslationData {
public $original = 'Node ID:';
public $translation = 'Knoop ID:';
public $comment = false;
public $status = 0;
},
);
This snippet above can of course not be parsed as valid PHP code. After thinking about it for a bit, I came up with a solution. Instead of the code above, we now generate:
array (
0 =>
ezcTranslationData::__set_state(array(
'original' => 'Node ID:',
'translation' => 'Knoop ID:',
'comment' => false,
'status' => 0,
)),
);
The __set_state() method is then required to be implemented by the class for this to work, but that is better than generating code which can never be parsed. The name comes from the Memento pattern . As this fixes a bug this made it into PHP 5.1.0 and PHP 6.0.0.
Life Line
I'm up early to get the Eurostar to #FOSDEM and I've already seen friends being made.
Fixed another address
Fixed address for flats
Fixed address, and ass missing service way
I walked 6.4km in 1h20m58s
I walked 11.4km in 9m22s
I walked 10.4km in 1h41m18s
I walked 7.4km in 1h26m49s
Good job antivaxer shit heads:
BBC News: UK loses measles elimination status
I walked 8.2km in 1h24m04s
We're about to celebrate the most famous Scottish poet!
I hiked 8.3km in 1h30m41s
Created a waste_basket
Created 2 waste_baskets
Created a bench
Created 4 benches
Created a waste_basket and a bench; Updated a toilet
Created a bench
Created an information
Updated a restaurant
Created 2 grit_bins
Created 2 waste_baskets
I hiked 20.5km in 3h52m17s
Updated a post_box
I walked 3.9km in 38m24s


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