|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-07-01 10:07 UTC] imaggens at gmail dot com
Description: ------------ First at all, one consideration about one of the informations provided in this form is the PHP version. I'm not using 5.3.6. I'm using 5.3.3, which is not listed. I f I chose "earlier", the form won't submit. I can be wrong, but I think this bug is not fixed in newer versions, because it's not a very common use. The whole thing is, when interfaces and classes are in the same namespace AND in same file, the 'implements' breaks the execution of the 'extends'. See Code #1 As expected I can see "Message from Second Class", without quotes. But if I add a interface (see Code #2) I get a Fatal Error: "Class 'Test\Zero' not found", when it could be expected the same result as before. But why this is important, if the best practices are to develop by following an organized structure, with each class/interface in its own file? The thing is, when DEVELOPING, this kind of organization is very useful, but if the code produced during development stage is a little library, if all the classes and interfaces are coded in one single file, only one call to require_once is needed, and the code execution is three times faster than when using an autoloader resource. Note about CodePad's codes: I'd only saved the lines of code in this site, they don't work from it, due PHP versions. But all the tests I made was in machine with the configurations posted. Test script: --------------- [ Code #1 ] http://codepad.org/pDOAiqBa [ Code #2 ] http://codepad.org/a42WgIT3 Expected result: ---------------- As said in Bug's Description, "Message from Second Class", witout quotes. Actual result: -------------- With the first code, I can see the expected result. With the second code, as I said, I see a Fatal Error. If the stack traces helps, here is it: Fatal error: Class 'Test\Test\Zero' not found in C:\root\Test\Library.php on line 5 Call Stack # Time Memory Function Location 1 0.0004 326896 {main}( ) ..\index.php:0 2 0.0018 334024 require_once( 'C:\root\Test\Framework.php' ) ..\index.php:3 Dump $_GET Dump $_POST PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 11:00:01 2025 UTC |
PHP expects the parent classes/interfaces to have been defined before the class that extends/implements them. If I change the order of the lines from code sample #2 (eIUJWp56) to read: <?php namespace Test { class Second { public function getMessage() { return 'Message from Second Class'; } } interface TestInterface {} abstract class Zero implements TestInterface { public function __construct() { // Using a second class $second = new Second; print $second -> getMessage(); } } class First extends Zero {} } ?> Then PHP 5.3.3, PHP 5.3.8 & PHP 5.4.0RC2 happily accept the file (no error).