Edit report at https://bugs.php.net/bug.php?id=41856&edit=1
ID: 41856
Comment by: pacerier at gmail dot com
Reported by: mbaynton at gmail dot com
Summary: support for anonymous classes
Status: Open
Type: Feature/Change Request
Package: *General Issues
PHP Version: 5.2.3
Block user comment: N
Private report: N
New Comment:
+1
Previous Comments:
------------------------------------------------------------------------
[2012-03-15 18:45:47] pajoye@php.net
Not exactly the same but look at closure and traits support in 5.4.
------------------------------------------------------------------------
[2012-03-15 18:35:55] david71rj at gmail dot com
+1
------------------------------------------------------------------------
[2011-11-09 11:34:50] antoniocs at gmail dot com
Would be nice to have this in Php 5.4 (or a latter version)
------------------------------------------------------------------------
[2011-05-25 19:02:47] urkle at outoforder dot cc
David, I do not believe you are understanding the request here.
I believe this is more what is being requested.
class Base {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function test() {
return $this->name;
}
}
$obj = new class extends Base {
public function test() {
return '<'.$this->name.'>';
}
};
echo $obj->test();
Basically similar to that of anonymous functions introduced in PHP 5.3
------------------------------------------------------------------------
[2010-09-26 19:41:30] david dot o dot greenberg at gmail dot com
The benefits of anonymous classes are twofold:
a) efficiency of code
b) efficiency of use of resources
consider:
$Div = new DivElement($InnerHTML = 'hello');
$Div->display();
versus:
(new DivElement( $InnerHTML = 'hello'))->display();
Lines of unnecessary code are saved, plus memory is allocated more efficiently.
This is especially useful for objects that merely appear for a single purpose and then vanish.
------------------------------------------------------------------------
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=41856--
Edit this bug report at https://bugs.php.net/bug.php?id=41856&edit=1