Doc #65930 [NEW]: new does not evaluate arguments if class has no constructor

From: Date: Fri, 18 Oct 2013 16:19:57 +0000
Subject: Doc #65930 [NEW]: new does not evaluate arguments if class has no constructor
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10507@lists.php.net to get a copy of this message
From: php at mlemoine dot name Operating system: Irrelevant PHP version: 5.5.5 Package: Documentation problem Bug Type: Documentation Problem Bug description:new does not evaluate arguments if class has no constructor Description: ------------ Either new \MyClass($foo->getBar()) is used or new $class($foo->getBar()) is used. If the instanciated class has no constructor explicitly defined or inherited, $foo->getBar() will never be invoked. This prevent any side-effect to be run and can produce very unexpected behaviour. This should either be fixed so the arguments are ALWAYS evaluated, or documented as such. CF example belows Test script: --------------- <?php class foo { public $i = 0; function createANewBar() { ++$i; return null; } } class no_construct { } class a_construct { public function __construct() { } } $myFoo = new foo; echo $myFoo->i.PHP_EOL; $class = 'no_construct'; $object = new $class($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; $object = new no_construct($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; $class = 'a_construct'; $object = new $class($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; $object = new a_construct($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; Expected result: ---------------- 0 1 2 3 4 Actual result: -------------- 0 0 0 1 2 -- Edit bug report at https://bugs.php.net/bug.php?id=65930&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65930&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65930&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65930&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65930&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65930&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65930&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65930&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65930&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65930&r=support Expected behavior: https://bugs.php.net/fix.php?id=65930&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65930&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65930&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65930&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65930&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65930&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65930&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65930&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65930&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65930&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65930&r=mysqlcfg

« previous php.doc.bugs (#10507) next »