From:             
Operating system: 
PHP version:      5.4.0alpha2
Package:          Class/Object related
Bug Type:         Feature/Change Request
Bug description:Traits vs Type hints

Description:
------------
Traits, when used in a class, are not added to class' type, and therefore
can not be use in type hints. The RFCs on traits
https://wiki.php.net/rfc/traits  and on horizontal reuse
https://wiki.php.net/rfc/horizontalreuse do not explain if this is by
design.

On the other hand Traits seem to share the same namespace as Classes and
Interfaces, since it is impossible to have an Interface and a Trait that
share the name ('Fatal error: Cannot redeclare class' is raised when this
is attempted).

Test script:
---------------
<?php
trait SomeTrait {}

class SomeClass {
  use SomeTrait;
}

$a = new SomeClass();

var_dump(is_a($a,'SomeTrait'));

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

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

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

Reply via email to