php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62218 Namespace conflict with Reflection
Submitted: 2012-06-03 20:10 UTC Modified: 2012-06-03 22:07 UTC
From: titch at tut dot by Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.4.3 OS: Ubuntu 12.04
Private report: No CVE-ID: None
 [2012-06-03 20:10 UTC] titch at tut dot by
Description:
------------
if namespace defined, ReflectionObject can't find class by name with namespace prefix

[Sun Jun 03 22:56:50 2012] [error] [client 127.0.0.1] PHP Fatal error:  Class 'MyProject\\ReflectionObject' not found in /var/www/myproject/MyClass.php on line 6

also namespaces doesn't works with ReflectionClass etc.

but all those scripts work without namespace

Test script:
---------------
//500 Internal Server Error
<?php
namespace MyProject;
class MyClass {
  function ff(){
    a = new ReflectionObject($this);
    echo 'it works';
  }
}
$a = new MyClass();
$a->ff();
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-03 20:15 UTC] titch at tut dot by
sorry, comment "//500 Internal Server Error" was added while posting
remove it, cause namespace must be first directive at script
but it's doesn't fix problem with Reflection, it just misspast
 [2012-06-03 22:03 UTC] mail+php at requinix dot net
So not resolved then? Okay. But not a bug.

As the error message states, PHP can't find MyProject\ReflectionObject. Because 
it's not there. It's at \ReflectionObject.

a = new \ReflectionObject($this);

Read up: php.net/language.namespaces
 [2012-06-03 22:07 UTC] titch at tut dot by
Thank you! Resolved.
 [2012-06-03 22:07 UTC] titch at tut dot by
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 00:01:30 2024 UTC