Re: Ability to assign new object to a class property.
| From: | Simon Schick | Date: | Sun, 15 Apr 2012 22:47:26 +0000 |
| Subject: | Re: Ability to assign new object to a class property. | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-59972@lists.php.net to get a copy of this message | ||
2012/4/13 Dmitri Snytkine <dsnytkine@ultralogistics.com>:
> I always wondered why can't we do something like this in php
>
> class MyClass{
>
> private $storage = new ArrayObject();
>
> public function __construct($v){
> // whatever
> }
>
> // rest of class
>
> }
>
> Why can't we create a new object and assign it to property like this?
>
> Then when a new instance of MyClass is created the $storage variable is
> automatically assigned a new ArrayObject.
> Somethink like this is valid, possible and commonly used in Java, why not in
> php?
>
> Has anyone already asked for this to be valid syntax in php?
>
> Dmitri Snytkine
> Web Developer
> Ultra Logistics, Inc.
> Phone: (888) 220-4640 x 2097
> Fax: (888) 795-6642
> E-Mail: dsnytkine@ultralogistics.com
> Web: www.ultralogistics.com
>
> "A Top 100 Logistics I.T. Provider in 2011"
>
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Hi, Dmitri
Just to add a random thought ....
When do you expect this code to be executed?
class Foo {
static public $foo = new StdClass();
}
Sorry if this code contains syntax-errors, but I think you'll still
get the point ;)
Bye
Simon