From:             
Operating system: 
PHP version:      5.4.1
Package:          Class/Object related
Bug Type:         Bug
Bug description:cannot use self in interface function declaration

Description:
------------
I am reviewing existing code on a PHP5.4.1 testbed. I've discovered that
interface declarations using 'self' as a type hint no longer allow
implementations to use 'self' but require them to use the interface name.

It is no longer possible for an interface to declare a method that requires
the implementor's class as a typehint without declaring that class
specifically. And that would limit the usefulness of that interface to one
class only.

Test script:
---------------
interface IComparable {
        public function equals(self $other);
}

class A implements IComparable{
        protected $var;
        
        public function __construct(self $v){
                $this->var=$v;
        }
        
        public function equals($other){
                return ($this->var == $other->var) ? 'equal' : 'different';
        }
}

$a1= new A(7);
$a2= new A(5);
$a3= new A(5);

echo $a1->equals($a2),"\n";
echo $a2->equals($a3),"\n";

Expected result:
----------------
different
equal


Actual result:
--------------
PHP Fatal error:  Declaration of A::equals() must be compatible with
IComparable::equals(IComparable $other) 

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

Reply via email to