Edit report at http://bugs.php.net/bug.php?id=50296&edit=1

 ID:                 50296
 Comment by:         m dot grundner at delegate dot at
 Reported by:        soapergem at gmail dot com
 Summary:            Automatically translate "self" in method_exists
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   Windows XP
 PHP Version:        5.3.1
 Block user comment: N
 Private report:     N

 New Comment:

Why don't you use method_exists(__CLASS__, "method")?


Previous Comments:
------------------------------------------------------------------------
[2009-11-25 17:24:05] soapergem at gmail dot com

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 this bug report at http://bugs.php.net/bug.php?id=50296&edit=1

Reply via email to