In my example the property was not static.
To make it clear - it cannot be static for this to work.

The instance of the class assigned to a property will be created when the 
object is created -most likely 
it will have to be done before the constructor is called so that the instance 
of property is available
to constructor.



Dmitri Snytkine
Web Developer
Ultra Logistics, Inc.
Phone: (888) 220-4640 x 2097
Fax: (888) 795-6642
E-Mail: dsnytk...@ultralogistics.com
Web: www.ultralogistics.com

"A Top 100 Logistics I.T. Provider in 2011"

-----Original Message-----
From: Simon Schick [mailto:simonsimc...@googlemail.com] 
Sent: Sunday, April 15, 2012 6:47 PM
To: Dmitri Snytkine
Cc: PHP Internals
Subject: Re: [PHP-DEV] Ability to assign new object to a class property.

2012/4/13 Dmitri Snytkine <dsnytk...@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: dsnytk...@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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to