ZF-6973: Zend_CodeGenerator_Php_Property can't be an Array
Description
Example:
new Zend_CodeGenerator_Php_Property
(
array
(
'name' => '_myProperty',
'visibility' => 'protected',
'defaultValue' => array('value1', 'value2')
)
)
out in the class
protected $_myProperty = 'array('value1', 'value2')';
So there is "extra" quotes
Comments
Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2009-06-11T04:14:28.000+0000
It can not be used with an Array?
Posted by MARTIN Nicolas (cocorambo) on 2009-06-11T04:42:09.000+0000
Add an example
Posted by Søren Haagerup (shaagerup) on 2009-06-27T11:52:53.000+0000
I can confirm this
When calling e.g.
the only thing that is generated is
When looking at the source code
it is obvious that it just casts the Array to a string, without doing anything sophisticated. I would expect it to "parse through" the array doing something like
I think I will implement it in my own ZF as a workaround for now. I don't know if there are any better (built-in?) solutions for this?
Posted by Søren Haagerup (shaagerup) on 2009-06-27T12:49:57.000+0000
should of course be
Let me know if you consider implementing something like the above in the official ZF - by then, I have likely implemented "pretty indenting" in the function as well..
Posted by Ralph Schindler (ralph) on 2009-06-28T13:15:52.000+0000
Fixed in r16344
Posted by Søren Haagerup (shaagerup) on 2009-06-29T00:53:58.000+0000
Thanks a lot - from the code it looks like it became a little more complicated when pretty-printing etc. was needed :-)
Do you have a recommended way of having objects as part of the default value?
My workaround for now is something like:
I am "misusing" the TYPE_NULL for getting it to render the value without quotes.
Posted by Søren Haagerup (shaagerup) on 2009-06-29T01:52:34.000+0000
Dang, what I wanted is actually not supported by PHP. Ignore my comment above for now..
Posted by Ralph Schindler (ralph) on 2009-06-29T06:46:07.000+0000
Ha, yeah. Property default values can only be scalar, constant and null. You'd want to populate with real objects at construction time. Rule of thumb is that CodeGenerator produces valid PHP code, so it attempts to play by all the rules of the language.
-ralph