# Question on arrays as properties

- Thread: https://externals.io/message/19775
- Original archive: https://news-web.php.net/php.internals/19775
- Started by Bob Silva on 2005-10-28T05:09:41+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19775 — Bob Silva — 2005-10-28T05:09:41+00:00

URL: https://externals.io/message/19775#19775

Hi,

 

Am I correct in saying that a class property cannot be initialized to an
array? Looking at zend_declare_property

it clearly states that Internal zvals cant be arrays.

 

So how would I go about creating the following inherited property in all my
subclasses if my core class has this property?

 

 

class ZObject {

 

protected $_props = array();

 

 

.

 

 

}

 

class ZString {

 

            public function __construct()

{

                        $this->setProperty($name, $value)

}

public function setProperty($name, $value)

{

                        $this->_props['value'];

}

 

}

 

In other words, how would I create a property that is an array (in C) where
that property is available to all my subclasses WITHOUT

initializing it manually in the __construct, which would force each subclass
constructor to call its parent (while good design, I'd prefer

not to have this constraint).

 

 

Thanks

 

Bob Silva

---

## #19776 — Michael Wallner — 2005-10-28T06:22:25+00:00

URL: https://externals.io/message/19775#19776 · In reply to: #19775

Hi Bob Silva, you wrote:

> Hi, In other words, how would I create a property that is an array
> (in C) where that property is available to all my subclasses WITHOUT 
> initializing it manually in the __construct, which would force each
> subclass constructor to call its parent (while good design, I'd
> prefer not to have this constraint).

No (really) other way.

Regards,
-- 
Michael - <mike(@)php.net> http://dev.iworks.at/ext-http/http-functions.html.gz
