Req #70919 [Sus]: class declarations may not be nested - why not!?
| From: | teo8976 at gmail dot com | Date: | Sun, 27 Mar 2016 09:39:01 +0000 |
| Subject: | Req #70919 [Sus]: class declarations may not be nested - why not!? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200155@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70919&edit=1
ID: 70919
User updated by: teo8976 at gmail dot com
Reported by: teo8976 at gmail dot com
Summary: class declarations may not be nested - why not!?
Status: Suspended
Type: Feature/Change Request
Package: Class/Object related
PHP Version: 7.0.0RC7
Block user comment: N
Private report: N
New Comment:
Oh, I see.
Anyway, if you need an RFC, this issue should stay open until somebody writes one. Writing an RFC is
part of fixing the issue (or the feature request if you prefer to call it that way).
Previous Comments:
------------------------------------------------------------------------
[2016-03-27 06:32:20] requinix@php.net
> You may have missed this:
HHVM is not PHP. They are separate entities.
------------------------------------------------------------------------
[2016-03-26 22:05:22] teo8976 at gmail dot com
> For this kind of change, an RFC is required.
You may have missed this:
> Note: this does work in hhvm. The fix should be backported to all supported versions.
------------------------------------------------------------------------
[2016-03-26 21:47:43] krakjoe@php.net
For this kind of change, an RFC is required.
Please see: https://wiki.php.net/rfc/howto
------------------------------------------------------------------------
[2015-11-16 22:28:29] teo8976 at gmail dot com
> There's no reason for that Sorter class to
> be declared within the function, can be declared outside of it like
> a normal class.
1) My code example is stupid, but there are PLENTY of reasons why you may want to declare it inside
a function. Of course you can declare it outside, but IT'S NOT THE SAME THING: if it is
declared inside the function, the class only exists if and after the function is executed.
2) That possibility has existed since PHP 5.0
3) If you can do it in a "global" function, there's no reason you shouldn't be
able to do it in a class method.
3) Note that in hhvm, rather than removing the ability to do it in a function, they have added the
ability to do it in a method. That is, they have fixed the bug already. I don't see a reason
why the fix shouldn't be backported to non-dead PHP versions.
------------------------------------------------------------------------
[2015-11-16 18:21:25] rahi at atsspec dot co
Neither should be valid; way too easy to write messed up code like this...declaring classes within
functions, seriously? WTF
There's no reason for that Sorter class to be declared within the function, can be declared
outside of it like a normal class.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=70919
--
Edit this bug report at https://bugs.php.net/bug.php?id=70919&edit=1