From:             soapergem at gmail dot com
Operating system: Windows XP
PHP version:      5.3.1
PHP Bug Type:     Feature/Change Request
Bug description:  Automatically translate "self" in method_exists

Description:
------------
In reference to bug #50289:

If I call method_exists("self", "method") from within a class, it 
should automatically translate "self" to the classname. Right now the 
behavior is not obvious; the behavior does not adhere to the KISS 
principle.

1. method_exists already can check for static methods.
2. "self" can already automatically translate to the current class 
name, for instance in call_user_func.
3. The most logical, simple and obvious expectation is that if you 
combine these two--you call method_exists with "self"--that it will 
automatically translate "self" to the current class name, and check 
for the method. Currently it does not. The current behavior is 
counterintuitive and confusing.

Making this change is not dangerous. Making this change will not cause 
any backwards-compatibility issues.

1. "self" is a reserved word. You cannot declare a class named "self"-
-this will issue a fatal error. So there is no possibility of any 
ambiguity. You cannot confuse "self" with any other class, because no 
other class can be named "self".

It does not make sense to have "self" work in some contexts but not in 
others. It would be better if it were consistent.

Reproduce code:
---------------
<?php
class Test
{
    public static function check()
    {
        var_dump(method_exists("self", "method"));
    }
    public static function method() { }
}
Test::check();
?>

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

-- 
Edit bug report at http://bugs.php.net/?id=50296&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50296&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50296&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50296&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50296&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50296&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50296&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50296&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50296&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50296&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50296&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50296&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50296&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50296&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50296&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50296&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50296&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50296&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50296&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50296&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50296&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50296&r=mysqlcfg

Reply via email to