# bad type specifier while parsing parameters

- Thread: https://externals.io/message/21172
- Original archive: https://news-web.php.net/php.internals/21172
- Started by Sebastian Bergmann on 2005-12-11T12:25:26+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

---

## #21172 — Sebastian Bergmann — 2005-12-11T12:25:26+00:00

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

The code below (which is based on Derick's code [1]) used to work until
 recently:

    <?php
    class ClassWithNonPublicProperties {
        protected $protectedProperty = 'foo';
        private $privateProperty = 'bar';
    }

    function getNonPublicProperty($object, $propertyName) {
        try {
            $class = new ReflectionClass($object);

            if ($class->hasProperty($propertyName)) {
                $property = $class->getProperty($propertyName);

                if (!$property->isPublic()) {
                    if ($property->isProtected()) {
                        $propertyName = "\0*\0" . $propertyName;
                    } else {
                        $propertyName = sprintf(
                          "\0%s\0%s",

                          get_class($object),
                          $propertyName
                        );
                    }

                    $tmp = (array) $object;

                    return $tmp[$propertyName];
                } else {
                    return $object->$propertyName;
                }
            } else {
                throw new InvalidArgumentException;
            }
        }

        catch (ReflectionException $e) {
            throw new InvalidArgumentException;
        }
    }

    $object = new ClassWithNonPublicProperties;

    print getNonPublicProperty($object, 'protectedProperty') . "\n";
    print getNonPublicProperty($object, 'privateProperty') . "\n";
    ?>

 The current PHP_5_1 prints

    Warning: ReflectionClass::getProperty():
    bad type specifier while parsing parameters in test.php on line 12

    Fatal error: Call to a member function isPublic() on a non-object
    in test.php on line 14

 Is this change in behaviour intentional or should I file a bug report
 for this?

 --
 [1] http://derickrethans.nl/private_properties_exposed.php

-- 
Sebastian Bergmann                      http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69

---

## #21173 — Marcus Boerger — 2005-12-11T12:36:40+00:00

URL: https://externals.io/message/21172#21173 · In reply to: #21172

Hello Sebastian,

  fixed in cvs - and btw it took me 5 seconds to fix - i bet you could have
done it yourself :-)

best regards
marcus

Sunday, December 11, 2005, 1:25:26 PM, you wrote:

>  The code below (which is based on Derick's code [1]) used to work until
>  recently:

>     <?php
>     class ClassWithNonPublicProperties {
>         protected $protectedProperty = 'foo';
>         private $privateProperty = 'bar';
>     }

>     function getNonPublicProperty($object, $propertyName) {
>         try {
>             $class = new ReflectionClass($object);

>             if ($class->hasProperty($propertyName)) {
>                 $property = $class->getProperty($propertyName);

>                 if (!$property->isPublic()) {
>                     if ($property->isProtected()) {
>                         $propertyName = "\0*\0" . $propertyName;
>                     } else {
>                         $propertyName = sprintf(
>                           "\0%s\0%s",

>                           get_class($object),
>                           $propertyName
>                         );
>                     }

>                     $tmp = (array) $object;

>                     return $tmp[$propertyName];
>                 } else {
>                     return $object->$propertyName;
>                 }
>             } else {
>                 throw new InvalidArgumentException;
>             }
>         }

>         catch (ReflectionException $e) {
>             throw new InvalidArgumentException;
>         }
>     }

>     $object = new ClassWithNonPublicProperties;

>     print getNonPublicProperty($object, 'protectedProperty') . "\n";
>     print getNonPublicProperty($object, 'privateProperty') . "\n";
>     ?>

>  The current PHP_5_1 prints

>     Warning: ReflectionClass::getProperty():
>     bad type specifier while parsing parameters in test.php on line 12

>     Fatal error: Call to a member function isPublic() on a non-object
>     in test.php on line 14

>  Is this change in behaviour intentional or should I file a bug report
>  for this?

>  --
>  [1] http://derickrethans.nl/private_properties_exposed.php

> -- 
> Sebastian Bergmann                      http://www.sebastian-bergmann.de/
> GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69




Best regards,
 Marcus
