Tuesday, 15 January 2019

php - Initialize class property with an anonymous function

Closures do not exist in PHP until PHP 5.3 (the latest version). Make sure you have PHP 5.3 if you want to do this.



In earlier versions, you can sort of duplicate this functionality with the create_function() function, somewhat like this:



$someFunc = create_function($args,$code);
$someFunc();


Where $args is a string formatted like "$x,$y,$z" and $code is a string of your PHP code.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...