Doc #52494 [NEW]: description of keyword "new"

From: Date: Fri, 30 Jul 2010 00:39:03 +0000
Subject: Doc #52494 [NEW]: description of keyword "new"
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-4774@lists.php.net to get a copy of this message
From: Operating system: PHP version: 5.3.3 Package: Documentation problem Bug Type: Documentation Problem Bug description:description of keyword "new" Description: ------------ URL I'm referring to is http://www.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.new 1) Documentation says that "To create an instance of a class, a new object must be created and assigned to a variable", though it doesn't really have to be assigned to a variable. 2) There is an example with storing class name in a variable and using this variable to create an object, i.e., $instance = new $className(), though this does not always work as expected with namespaced classes (I'm not sure if this is a "documentation problem" or a bug). It would be worth noting that namespaced classes need a full name to be stored in variable, even if it is being used the same namespaced. See a test script for an example. Test script: --------------- <?php namespace MyNamespace { class MyClass { function __construct() { echo __METHOD__, "\n"; } } $obj = new MyClass(); // works $obj = new \MyNamespace\MyClass(); // works $obj = new MyNamespace\MyClass(); // does not work, resolves as MyNamespace\MyNamespace\MyClass $className = '\\MyNamespace\\MyClass'; $obj = new $className(); // works, as $className includues namespace $className = 'MyNamespace\\MyClass'; $obj = new $className(); // still works, as it resolves as <global namespace>\MyNamespace\MyClass $className = 'MyClass'; $obj = new $className(); // does not work } Expected result: ---------------- MyNamespace\MyClass::__construct MyNamespace\MyClass::__construct PHP Fatal error MyNamespace\MyClass::__construct MyNamespace\MyClass::__construct PHP Fatal error Actual result: -------------- MyNamespace\MyClass::__construct MyNamespace\MyClass::__construct PHP Fatal error MyNamespace\MyClass::__construct PHP Fatal error MyNamespace\MyClass::__construct -- Edit bug report at http://bugs.php.net/bug.php?id=52494&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52494&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52494&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52494&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52494&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52494&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52494&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52494&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52494&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52494&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52494&r=support Expected behavior: http://bugs.php.net/fix.php?id=52494&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52494&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52494&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52494&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52494&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52494&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52494&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52494&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52494&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52494&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52494&r=mysqlcfg

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