# Problem with (namespaced) code extending ReflectionProperty - possible bug?

- Thread: https://externals.io/message/42141
- Original archive: https://news-web.php.net/php.internals/42141
- Started by Karsten Dambekalns on 2008-12-08T11:10:27+00:00
- Messages: 7
- 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

---

## #42141 — Karsten Dambekalns — 2008-12-08T11:10:27+00:00

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

Hi.

Running 5.3.0alpha3 now and converting our codebase to the new 
namespaces syntax. Works fine so far, the new name resolution rules are 
very usable and lead to cleaner code so far. :)

Now I ran into a problem. We have a class extending ReflectionProperty, 
and I got a complaint about the signature of our getValue() not matching 
that of the parent class. Ok, I added that stdclass type hint, fine. I 
thought.

Later on it turned out that I need to make that type hint \stdclass as 
our code is namespaced and I got an error because My\NS\stdclass could 
not be found. Now I got that signature mismatch warning again. Bummer. I 
decided to build a small test case, and now the fun starts.

According to the manual and the PHP source the signature is this:
  public function getValue(stdclass $object)

This is my test code:
  ---- snip ----
<?php
class PropertyReflection extends ReflectionProperty {
	public function getValue(stdclass $object) {}
}
?>
  ---- snip ----

and the result of running that is:
  ---- snip ----
Declaration of PropertyReflection::getValue() should be compatible with 
that of ReflectionProperty::getValue()
  ---- snip ----

I get that result even when using
  * no type hint
  * stdClass

The result stays the same when adding a namespace declaration and 
adjusting the typehint variations accordingly.

Can anybody shed some light on this? Or should I file a bug report right 
away?

Thanks,
Karsten

---

## #42151 — Stanislav Malyshev — 2008-12-08T15:50:52+00:00

URL: https://externals.io/message/42141#42151 · In reply to: #42141

Hi!

> According to the manual and the PHP source the signature is this:
>  public function getValue(stdclass $object)

Manual is unfortunately not exact in this point - true signature for it 
is public function getValue([object $object]) - i.e. $object is not 
required and if it's supplied, it doesn't have to be stdclass - any 
object will do. Thus, engine correctly complains that your signature - 
required object of stdclass - is not compatible.

> 
> This is my test code:
>  ---- snip ----
> <?php
> class PropertyReflection extends ReflectionProperty {
>     public function getValue(stdclass $object) {}
> }
> ?>

Use public function getValue($object = null) {} instead.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #42160 — Marcus Boerger — 2008-12-08T16:27:40+00:00

URL: https://externals.io/message/42141#42160 · In reply to: #42151

Hello Stanislav,

Monday, December 8, 2008, 4:50:52 PM, you wrote:

> Hi!

> > […]

> Manual is unfortunately not exact in this point - true signature for it 
> is public function getValue([object $object]) - i.e. $object is not 
> required and if it's supplied, it doesn't have to be stdclass - any 
> object will do. Thus, engine correctly complains that your signature - 
> required object of stdclass - is not compatible.

Which reminds me that we still have no way to do that in userland.
In userland you cannot write:
  function foo(Object $bla = NULL).
The missing part is 'Object' as a type hint. I once long ago suggested
using 'class' as in 'any class member'. But people felt it wouldn't be
self explanatory enough. And unfortunately we cannot use 'Object' for
obvious reasons. We simply cannot turn that into a reserved word not
can we expect no one to have a class named Object already.

So my suggestion holds: Let's add type hint 'class' to allow hints for
objects.

marcus

> > […]

> Use public function getValue($object = null) {} instead.
> -- 
> Stanislav Malyshev, Zend Software Architect
> stas@zend.com   http://www.zend.com/
> (408)253-8829   MSN: stas@zend.com




Best regards,
 Marcus

---

## #42164 — Rodrigo Saboya — 2008-12-08T16:48:00+00:00

URL: https://externals.io/message/42141#42164 · In reply to: #42160

> Which reminds me that we still have no way to do that in userland.
> In userland you cannot write:
>   function foo(Object $bla = NULL).
> The missing part is 'Object' as a type hint. I once long ago suggested
> using 'class' as in 'any class member'. But people felt it wouldn't be
> self explanatory enough. And unfortunately we cannot use 'Object' for
> obvious reasons. We simply cannot turn that into a reserved word not
> can we expect no one to have a class named Object already.
> 
> So my suggestion holds: Let's add type hint 'class' to allow hints for
> objects.
> 
> marcus
> 
> > […]
> 
> > […]
> 
> 
> 
> 
> Best regards,
>  Marcus
> 

I don't think having a Object class built in is such a big issue with 
namespaces around. Anyone using object type-hinting should have a clue.

--
Rodrigo Saboya

---

## #42169 — Marcus Boerger — 2008-12-08T17:12:08+00:00

URL: https://externals.io/message/42141#42169 · In reply to: #42164

Hello Rodrigo,

Monday, December 8, 2008, 5:48:00 PM, you wrote:

> > […]

> I don't think having a Object class built in is such a big issue with 
> namespaces around. Anyone using object type-hinting should have a clue.

I am not speaking of a built-in object class. Because that is not what the
internal parsing does. The internal parsing checks whether a passed-in
argument is an instance of any class or not. And we can never have one base
class. The engine simply would not allow that becasue it can take instances
created from classes provided by different back-ends including other
lanugae runtimes.

> --
> Rodrigo Saboya




Best regards,
 Marcus

---

## #42170 — Stanislav Malyshev — 2008-12-08T17:15:51+00:00

URL: https://externals.io/message/42141#42170 · In reply to: #42169

Hi!

> I am not speaking of a built-in object class. Because that is not what the
> internal parsing does. The internal parsing checks whether a passed-in

Right now internal parser is quite detached from what PHP functions 
could do. If someone would write a proposal to bring them closer 
together (including all the things like conversions, maybe even combined 
types like "array or object" :) then I think it'd be cool.

-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #42196 — Karsten Dambekalns — 2008-12-09T09:47:41+00:00

URL: https://externals.io/message/42141#42196 · In reply to: #42151

Hi.

Stanislav Malyshev wrote:
> > […]
  ...
> Use public function getValue($object = null) {} instead.

Thanks, that works! I saw the [] in the C source, but failed to draw the 
right conclusion...

Regards,
Karsten

PS: Having a way to type hint on any object would be cool!
