note 92208 modified in functions.anonymous by danbrown

From: Date: Tue, 14 Jul 2009 14:45:27 +0000
Subject: note 92208 modified in functions.anonymous by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158279@lists.php.net to get a copy of this message
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; ?> --was-- Perhaps you'll find yourself wanting doing a wicked thing like: $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. class Helloworld{ function __toString(){ return("each hello world is different...".date("His")); } } $helloworld = new Helloworld(); echo $helloworld; sleep(5); echo $helloworld; http://php.net/manual/en/functions.anonymous.php

« previous php.notes (#158279) next »