Doc #52494 [Opn->Csd]: description of keyword "new"
| From: | degeberg@php.net | Date: | Sun, 15 Aug 2010 07:40:06 +0000 |
| Subject: | Doc #52494 [Opn->Csd]: description of keyword "new" | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4861@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52494&edit=1
ID: 52494
Updated by: degeberg@php.net
Reported by: delphists at apollo dot lv
Summary: description of keyword "new"
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: 5.3.3
-Assigned To:
+Assigned To: degeberg
Block user comment: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2010-08-15 09:39:54] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=302259
Log: Fixed PHP bug #52494 (description of keyword "new")
------------------------------------------------------------------------
[2010-07-30 02:39:03] delphists at apollo dot lv
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 this bug report at http://bugs.php.net/bug.php?id=52494&edit=1