php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60833 self, parent, static behave inconsistently case-sensitive
Submitted: 2012-01-21 20:31 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mario at include-once dot org Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4.0RC6 OS: Linux
Private report: No CVE-ID: None
 [2012-01-21 20:31 UTC] mario at include-once dot org
Description:
------------
"parent" and "self", "static" LSB tokens behave inconsistent when it comes to case-sensitivity. Class names in PHP are case-insensitive, but these three keywords aren't always, as the parser sees them as raw T_STRINGs.

That is, you cannot do `SELF::CNST` or `SELF::$VAR` or `SELF::METHOD()`
But it's possible to use `constant("SELF::CNST")` or `call_user_func` with uppercase `SELF` keyword.

Likewise do you get an error message for `class SELF {}` declarations, even if the other error messages indicate the uppercase class name wasn't reserved.

----

Patch: It's just a matter of exchanging `memcmp` against `strncasecmp` in `zend_get_class_fetch_type`. Not sure if that is a sufficient substition though. It works well, and all comparisons are shadowed by a length check anyway, so little worries about NUL byte length discrepancies.
Performance: No idea. This affects the parser, hard to test without memory exhausting script (eval to redeclare classes). But in clang build no measurable difference (again, pointless test with only x10000 runs).

----

Should this be fixed?
Well, of course. This might not matter to most people, never run into this myself IIRC, but it does in fact come up as issue occasionally:
http://stackoverflow.com/questions/8953208/fatal-error-class-self-not-found
Also because it's not mentioned in the manual yet.
http://www.php.net/manual/en/language.oop5.late-static-bindings.php
(I shall commit a note there myself...)
And of course, the whole PHP 5.3 series doesn't support it. But that doesn't mean it shouldn't be normalized in later versions, specifically the upcoming 5.4. ("Never too later to fix a mistake.." bla bla)


Test script:
---------------
class a {
    const C = "C";
    function __construct() {
        print SELF::C;
    }

}
new a;



Patches

self-parent-static-token-case-insensitive (last revision 2012-01-21 20:32 UTC by mario at include-once dot org)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-28 02:07 UTC] stas@php.net
-Status: Open +Status: Closed
 [2013-01-28 02:07 UTC] stas@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=184db665ebdb6a2717d15e956391f6d88e1d05c6
Log: fix bug #60833 - self, parent, static behave inconsistently case-sensitive
 [2013-11-17 09:31 UTC] laruence@php.net
Automatic comment on behalf of stas
Revision: http://git.php.net/?p=php-src.git;a=commit;h=184db665ebdb6a2717d15e956391f6d88e1d05c6
Log: fix bug #60833 - self, parent, static behave inconsistently case-sensitive
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC