#46225 [NEW]: Allow for optional arguments to __toString() magic method

From: Date: Fri, 03 Oct 2008 15:28:30 +0000
Subject: #46225 [NEW]: Allow for optional arguments to __toString() magic method
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129441@lists.php.net to get a copy of this message
From: phpbugs at sevenlight dot com Operating system: OSX 10.5.5 PHP version: 5.3.0alpha2 PHP Bug Type: Feature/Change Request Bug description: Allow for optional arguments to __toString() magic method Description: ------------ I believe it should be possible to have optional arguments to the __toString() magic method to allow for explicitly changing the behaviour of this function. I understand why you cannot have any required arguments, but I do not see why it would not be possible to have optional arguments that would define the default behaviour. Reproduce code: --------------- class Test { public function __toString($bDebug = FALSE) { return $bDebug ? 'This is the debugging output' : 'This is the default output'; } } $o = new Test(); echo $o . "\n"; echo $o->__toString(TRUE) . "\n"; Expected result: ---------------- This is the default output This is the debugging output Actual result: -------------- Fatal error: Method Test::__tostring() cannot take arguments in /srv/www/test/toString.php on line 3 -- Edit bug report at http://bugs.php.net/?id=46225&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46225&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46225&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46225&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46225&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46225&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46225&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46225&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46225&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46225&r=support Expected behavior: http://bugs.php.net/fix.php?id=46225&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46225&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46225&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46225&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46225&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46225&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46225&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46225&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46225&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46225&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46225&r=mysqlcfg

« previous php.bugs (#129441) next »