Edit report at http://bugs.php.net/bug.php?id=6418&edit=1

 ID:               6418
 Comment by:       tom at tomwardrop dot com
 Reported by:      nathan at cjhunter dot com
 Summary:          Multiple class extends ordering error
 Status:           Wont fix
 Type:             Feature/Change Request
 Package:          Feature/Change Request
 Operating System: Linux 2.0.36
 PHP Version:      4.0.1pl2

 New Comment:

I don't know the internals of PHP, but maybe someone who does can
respond to this. I agree with the comment by bj...@php.net...



"You need to declare the class before you use it.

The other way around doesn't make sense and will not ever 

be supported."



However, since when was declaring a class considered to be "using" a
class? If possible, I propose that PHP check for the availability of
extended classes and interfaces at the time an instance is created, or
when the first static call is made, rather than when the class is
declared. This is no doubt the most logical approach, but I have no idea
whether this is technically possible to implement.



We can call this feature, just-in-time class checking :-)



I look forward to hearing a response from someone who knows the part of
the PHP core that handles this.


Previous Comments:
------------------------------------------------------------------------
[2007-01-07 11:26:07] bj...@php.net

You need to declare the class before you use it.

The other way around doesn't make sense and will not ever 

be supported.



With the "class per file" approach you can use autoload() 

or spl_autoload()

------------------------------------------------------------------------
[2006-07-15 10:20:15] info at triin dot net

I had some quite hard time figuring out what is wrong with my code -
this defenetly is a bug, not a feature request.



I had a lot of PHP files (class in each file) and at the beginning of
each one there were the require_once statements to include all the other
classes that were used by that class. And suddenly there was a weird
collision...

------------------------------------------------------------------------
[2002-09-09 09:04:35] scallop at iki dot fi

Yes, this is a feature that is definately needed in PHP.



I am currently working on a project which has very complex class
hierarchy (dozens of classes extending each other). Due to complex class
hierarchy and the huge amount of code, I am developing classes so that
each class is in it's own file. And to make it all simple, I use a small
script to combine all this classes into one huge file.



It is always possible to create a system that checks class dependencies
and creates a combined classfile with classes in proper order.



However, I think this is a feature that _should_ be provided by php.



(tested on versions 4.2.3, 4.3.0 - still not implemented)



I hope I explained my self clear enough.



See my report (marked as duplicate):

http://bugs.php.net/bug.php?id=19312

------------------------------------------------------------------------
[2000-08-31 08:48:21] s...@php.net

Yes, you cannot do this in PHP. In fact, you even shouldn't try doing
this - why would you need to define class without knowing what it
extends? I move it to feature request in the meantime, in case something
will explain why this could be useful.

------------------------------------------------------------------------
[2000-08-29 12:20:10] nathan at cjhunter dot com

Multiple class extends creates ordering error



The below..

<?

class c extends b {}



class b extends a {}



class a {}

?>



gives an error 'Fatal error: Class c: Cannot inherit from undefined
class b in test.html on line 4',

but..



<?

class b extends a {}



class a {}



// class c moved to bottom

class c extends b {}

?>



works fine.



I imagine this could be fixed by first ordering the classes by their
given dependencies and then process them one by one.

------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=6418&edit=1

Reply via email to