note 92208 rejected from functions.anonymous by nicobn
| From: | nicobn@php.net | Date: | Wed, 03 Nov 2010 21:44:20 +0000 |
| Subject: | note 92208 rejected from functions.anonymous by nicobn | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173725@lists.php.net to get a copy of this message | ||
Note Submitter: ulderico at maber dot com dot br
----
Perhaps you'll find yourself wanting doing a wicked thing like:
<?php
$helloworld = function(){
return "each hello world is different... ".date("His");
};
echo $helloworld;
?>
which throws:
Catchable fatal error: Object of class String could not be converted to string
OK... Here's the way of doing this.
<?php
class Helloworld{
function __toString(){
return("each hello world is different...".date("His"));
}
}
$helloworld = new Helloworld();
echo $helloworld;
sleep(5);
echo $helloworld;
?>