#34697 [Opn]: Undocumented behaviour: class definition before use
| From: | direvus at gmail dot com | Date: | Sun, 02 Oct 2005 22:58:57 +0000 |
| Subject: | #34697 [Opn]: Undocumented behaviour: class definition before use | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969370411@lists.php.net to get a copy of this message | ||
ID: 34697
User updated by: direvus at gmail dot com
Reported By: direvus at gmail dot com
Status: Open
Bug Type: Documentation problem
Operating System: Linux
PHP Version: Irrelevant
New Comment:
> I doubt anyone will know exactly what are the features that will
make
you have to declare the class prior of its usage.
Well somebody wrote the code that causes this behaviour, so somebody
must know about it. Unless it's unintended.
> Anyway, declaring the
class before its usage has some performance advantages.
That's good to know, and should also be noted in the manual.
Don't get me wrong, I'm all for declaring classes prior to usage. I
think it's much better programming style. But there's a big difference
between "it's good style" and "the language requires it". A difference
that needs to be well documented.
Previous Comments:
------------------------------------------------------------------------
[2005-10-02 22:58:49] nlopess@php.net
I doubt anyone will know exactly what are the features that will make
you have to declare the class prior of its usage. Anyway, declaring the
class before its usage has some performance advantages.
However I couldn't find this info in the language.oop5 chapter, so I'm
leaving this open to add a note to that page.
------------------------------------------------------------------------
[2005-10-02 22:26:36] direvus at gmail dot com
No, it doesn't.
It says "some of the new features of PHP5". That's extremely
non-specific. It could mean that only a couple of the new features
cause the restriction, or it could mean that all of them do.
And I'd like to reiterate my point that, regardless of how clear the
mention is, it is not where it needs to be. It needs to be in the
manual *and* in the migration guide.
This is a significant (and again, peculiar) property of PHP5 class
syntax. It's just not right to leave it out of the manual.
Whether you think the existing sentence is sufficient or not, how is
the manual not improved by adding this?
------------------------------------------------------------------------
[2005-10-02 18:21:56] nlopess@php.net
I think it is clear enough.
It says that if you use the "new" PHP 5 features (interfaces,
inheritance,..) you must declare the class before using it.
------------------------------------------------------------------------
[2005-10-01 03:12:54] direvus at gmail dot com
Description:
------------
In the php5 migration guide, we have
"In some cases classes must be declared before used. It only happens
only if some of the new features of PHP 5 are used. Otherwise the
behaviour is the old."
I request that this behaviour be documented properly (which features?
And why?) in the manual chapter on Classes and Objects in PHP5.
I think for most people who are accustomed to PHP definition
conventions, this will come as a surprise. Functions never need to be
declared before use. Even methods within a class definition need not
be declared before use. So why do we have this strange requirement in
the declaration of classes?
This vague mention in the migration guide really isn't sufficient ...
it's a strange and opaque behaviour whether you're migrating code or
not.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34697&edit=1