From:             eric at wepay dot com
Operating system: OS X, CentOS
PHP version:      5.3.14
Package:          Class/Object related
Bug Type:         Bug
Bug description:Incorrect strong typing in namespaced child classes

Description:
------------
If a namespaced class extends a non-namespaced abstract class, typehinted
method 
parameters are not checked correctly by the interpreter. The code sample
shows 
this best, but basically the child class implementing the abstract methods
isn't 
correctly checking how namespaces will apply to typehinted parameters as
they were 
declared in the base class. While the code aesthetically looks the same,
the 
parser (as expected) interprets the typehints in the namespaced class to be
based 
on the current namespace when not explicity specified, but this
unintentionally 
changes the signature of the methods from that of the abstract class.



Test script:
---------------
========================base.php
<?php

class Payment {}
abstract class CreditCardProcessor {
        abstract function AuthorizePayment(Payment $p);
}


========================run.php
<?php

namespace processors\credit_card;
require_once 'base.php';
class ipc extends \CreditCardProcessor {
        function AuthorizePayment(Payment $p) {
        }
}

$p = new \Payment;
$ipc = new ipc;
$ipc->AuthorizePayment($p);




// note that if processors\credit_card\ipc::AuthorizePayment() is declared
as (\Payment $p) instead of (Payment $p), everything behaves as expected
since the base class is actually expecting a \Payment object


Expected result:
----------------
PHP Fatal error:  Declaration of
processors\credit_card\ipc::AuthorizePayment() 
must be compatible with that of CreditCardProcessor::AuthorizePayment() in

/Users/eric/dev/run.php on line 5


Actual result:
--------------
PHP Catchable fatal error:  Argument 1 passed to 
processors\credit_card\ipc::AuthorizePayment() must be an instance of 
processors\credit_card\Payment_Model, instance of Payment_Model given,
called in 
/Users/eric/dev/run.php on line 12 and defined in /Users/eric/dev/run.php
on line 
6

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

Reply via email to