Req #61759 [Com]: class_alias() should accept classes with leading backslashes
| From: | contact at jubianchi dot fr | Date: | Tue, 27 Aug 2013 10:19:53 +0000 |
| Subject: | Req #61759 [Com]: class_alias() should accept classes with leading backslashes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181237@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61759&edit=1
ID: 61759
Comment by: contact at jubianchi dot fr
Reported by: aharvey@php.net
Summary: class_alias() should accept classes with leading
backslashes
Status: Open
Type: Feature/Change Request
Package: Class/Object related
Operating System: Irrelevant
PHP Version: master-Git-2012-04-18 (Git)
Block user comment: N
Private report: N
New Comment:
I agree with Johannes about consistency.
The severity is not really is not very high and this use case can easily be
handled at a useland level.
As long as this behavior is not "fixed" I think a warning on the doc shoudl be
enough, even if I'd like to see it fixed (but as I said, it's not a big deal at
the moment).
BTW, thanks for you work Julien :)
Previous Comments:
------------------------------------------------------------------------
[2013-08-27 10:08:00] johannes@php.net
Technically we could, but it adds some inconsistency if one place allows this but others not and
that should be avoided.
------------------------------------------------------------------------
[2013-08-27 09:46:53] jpauli@php.net
The following patch has been added/updated:
Patch Name: fix-class_alias
Revision: 1377596813
URL: https://bugs.php.net/patch-display.php?bug=61759&patch=fix-class_alias&revision=1377596813
------------------------------------------------------------------------
[2013-08-27 09:45:12] jpauli@php.net
Johannes: I agree, but we could start by patching this bug report right?
I got a patch here : https://github.com/jpauli/php-
src/compare/class_alias_registration_fix
------------------------------------------------------------------------
[2013-08-26 18:32:26] johannes@php.net
Note: The bug report is too restrictive. A proper patch would have to work on all places where
classnames come from string context. This at first means verifying that all places go via
zend_lookup_class() and related functions, not EG(class_table) / CG(class_table)
------------------------------------------------------------------------
[2013-08-26 18:13:08] contact at jubianchi dot fr
I experienced the exact same issue on PHP 5.4.17 on OS X 10.9 (Mavericks DP6).
I wrote a simple test case, here it is :
Test script:
---------------
namespace jubianchi\Alias {
class A {}
var_dump(class_alias('\\jubianchi\\Alias\\A', 'C'));
$reflector = new \ReflectionClass('C');
var_dump($reflector->getName());
var_dump(class_alias('\\jubianchi\\Alias\\A', '\\jubianchi\\Alias\\B'));
try {
$reflector = new \ReflectionClass('\\jubianchi\\Alias\\B');
var_dump($reflector->getName());
} catch(\Exception $e) {
var_dump(get_class($e) . ': ' . $e->getMessage());
}
var_dump(class_alias('\\jubianchi\\Alias\\A', 'jubianchi\\Alias\\B'));
$reflector = new \ReflectionClass('\\jubianchi\\Alias\\B');
var_dump($reflector->getName());
}
Expected result:
----------------
bool(true)
string(17) "jubianchi\Alias\A"
bool(true)
string(17) "jubianchi\Alias\A"
bool(true)
string(17) "jubianchi\Alias\A"
Or:
----------------
bool(true)
string(17) "jubianchi\Alias\A"
bool(false)
string(60) "ReflectionException: Class \jubianchi\Alias\B does not exist"
bool(true)
string(17) "jubianchi\Alias\A"
Actual result:
----------------
bool(true)
string(1) "A"
bool(true)
string(17) "jubianchi\Alias\A"
bool(true)
string(60) "ReflectionException: Class \jubianchi\Alias\B does not exist"
bool(true)
string(17) "jubianchi\Alias\A"
As you can see, class_alias returns bool(true) as if everything went fine, so we
expect the alias to be available but a reflection on the latter throws an
exception.
I think class_alias should be able to handle the leading backslashes or return
bool(false) if it can't.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61759
--
Edit this bug report at https://bugs.php.net/bug.php?id=61759&edit=1