#46373 [NEW]: Type-Hinting with namespaces does not work

From: Date: Thu, 23 Oct 2008 18:50:08 +0000
Subject: #46373 [NEW]: Type-Hinting with namespaces does not work
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-130014@lists.php.net to get a copy of this message
From: phpbugs at sevenlight dot com Operating system: OSX 10.5.5 PHP version: 5.3CVS-2008-10-23 (snap) PHP Bug Type: Scripting Engine problem Bug description: Type-Hinting with namespaces does not work Description: ------------ Using a type-hint with a namespace does not work. It allows an object of a different class to be passed, and even allows a bogus namespace to be used. It will also allow null variables, and will pass through any value, no matter what class type-hinting you use. Unfortunately, in my simplest test cases I have not been able to reproduce it, it is only in my larger project that it causes this problem. I really don't know where to start with this, and how to duplicate it. Needless to say, have provided the failing code from my project. The entire project is several thousand lines of code. And I've really done my best to track down the problem, even using the 5.3-alpha3-dev. I'll include the code that causes the problem. I really don't know what's wrong, and why it is doing it. Any hints as to what I might be able to do to try to reproduce this in a simpler way would be nice, but I really don't know where to go from here. Reproduce code: --------------- <?php namespace MyNamespace; class MyClass { // execute public function execute() { $this->test(NULL); return $this->_execute($this->_mc); } protected function test(MyBogusNamespace::MyBogusClass $m) { $reflect = new ReflectionClass(get_class($this)); $method = $reflect->getMethod('test'); echo $method; var_export($m); echo "\n\nClass: " . get_class($m) . " == MyBogusNamespace::MyBogusClass\n\n"; } } ?> Expected result: ---------------- Catchable fatal error: Argument 1 passed to MyNamespace::MyClass::test() must be an instance of MyBogusNamespace::MyBogusClass, null given, called in /srv/www/test/ns/new.php on line 9 and defined in /srv/www/test/ns/new.php on line 13 Actual result: -------------- Method [ <user> protected method test ] { @@ /srv/spin/spin4/spinnaker/extender/universal/tablelibrary.php 73 - 80 - Parameters [1] { Parameter #0 [ <required> MyBogusNamespace::MyBogusClass $m ] } } NULL == MyBogusNamespace::MyBogusClass -- Edit bug report at http://bugs.php.net/?id=46373&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46373&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46373&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46373&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46373&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46373&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46373&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46373&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46373&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46373&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46373&r=support Expected behavior: http://bugs.php.net/fix.php?id=46373&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46373&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46373&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46373&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46373&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46373&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46373&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46373&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46373&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46373&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46373&r=mysqlcfg

« previous php.bugs (#130014) next »