ZF-2526: Zend_Form_Element::getAttribs() returns an empty array

Issue Type: Patch Created: 2008-01-30T07:12:16.000+0000 Last Updated: 2008-01-30T15:31:16.000+0000 Status: Resolved Fix version(s): Reporter: Mark Maynereid (mim) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: - ZF-2518



I can't get Zend_Form's elements to render "title" attributes and it appears to be because Zend_Form_Element's getAttribs() method does not return attributes that have been previously set (while getAttrib() works fine). Here's how I reproduce the problem:

<pre class="highlight">
$options = array(
    'title' => 'my summary',
    'name' => 'username',
    'label' => 'Username',
$username = new Zend_Form_Element_Text($options);

array(0) {

I suspect this is a new PHP bug (I use PHP 5.2.0-8+etch9), whereby declaring $this->$someprop does not give it any visibility and so this is why the reflection isPublic() test in getAttribs() fails incorrectly.

I've written the following patch which seems to correct the problem:

<pre class="highlight">
Index: incubator/library/Zend/Form/Element.php
--- incubator/library/Zend/Form/Element.php     (revision 7696)
+++ incubator/library/Zend/Form/Element.php     (working copy)
@@ -493,8 +493,11 @@
         $properties = $r->getProperties();
         $attribs = array();
         foreach ($properties as $property) {
-            if ($property->isPublic()) {
-                $attribs[$property->getName()] = $property->getValue($this);
+            if (! $property->isPrivate() &&
+                ! $property->isProtected() &&
+                ! $property->isStatic()
+            ) {
+                $attribs[$property->getName()] = $this->getAttrib($property->getName());


Posted by Mark Maynereid (mim) on 2008-01-30T09:22:06.000+0000

The code below takes Zend Framework out of the loop, and tests the problem directly.

Please try the code. Does anyone have the same output as me with myRuntimeProperty missing in the var_dump? If you do, I think Zend_Form_Element::getAttribs() will not work with your PHP version, and maybe I should raise it on Any comments appreciated.

<pre class="highlight">

class Test
    public $myDeclaredProperty = 1;

    public function __construct()
        $this->myRuntimeProperty = 2;

    public function getPublicProperties()
        $r = new ReflectionObject($this);
        $properties = $r->getProperties();
        $publicProperties = array();
        foreach ($properties as $property) {
            if ($property->isPublic()) {
                $publicProperties[$property->getName()] = 
        return $publicProperties;
echo 'Running ' . phpversion() . "\n";
$obj = new Test();
echo "Dumping object:\n";
echo "Dumping public properties according to Reflection object\n";

My output. Note myRuntimeProperty is missing in the second var_dump:

<pre class="highlight">
Running 5.2.0-8+etch9
Dumping object:
object(Test)#1 (2) {
Dumping public properties according to Reflection object
array(1) {

Posted by Matthew Weier O'Phinney (matthew) on 2008-01-30T15:30:31.000+0000

Duplicates ZF-2518, already reported.

Posted by Matthew Weier O'Phinney (matthew) on 2008-01-30T15:31:16.000+0000

Resolved in r7708, using the same logic used in Zend_View_Abstract::getVars() (known to work in PHP >= 5.1.4)

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.