php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54103 Cannot create an object reference from a variable with namespaces.
Submitted: 2011-02-26 05:36 UTC Modified: 2011-02-26 13:22 UTC
From: sam at bike-this dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.5 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sam at bike-this dot com
New email:
PHP Version: OS:

 

 [2011-02-26 05:36 UTC] sam at bike-this dot com
Description:
------------
When creating a new object reference with variables and namespaces (tested with aliasing namespaces [use namespace as alias] and not [\long\namespace\path]) and it fails in both scenarios.

This works without the use of namespaces. This bug seems like an overlooked feature.

Test script:
---------------
# test.php
<?php
use Test as T;
require "namespace_test.php";
$name = "MyClass";
$obj = new T\$name;
?>

# namespace_test.php
<?php
namespace Test {
    class MyClass {
	function __construct() {
	    echo "Testing!";
	}
    }
}
?>

Expected result:
----------------
Testing!

Actual result:
--------------
Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in test.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-26 13:20 UTC] cataphract@php.net
-Type: Bug +Type: Feature/Change Request
 [2011-02-26 13:22 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2011-02-26 13:22 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See http://php.net/manual/en/language.namespaces.dynamic.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 12:01:27 2025 UTC