Bug #68485 [Nab]: late namespace resolution with cross-namespace inheritance missing
Edit report at https://bugs.php.net/bug.php?id=68485&edit=1
ID: 68485
User updated by: llmll at gmx dot de
Reported by: llmll at gmx dot de
Summary: late namespace resolution with cross-namespace
inheritance missing
Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: any
PHP Version: 5.5.19
Block user comment: N
Private report: N
New Comment:
Sorry, but you are wrong again. Please double check your own PHP documentation, where it says:
"Inside namespace (say A\B), calls to **unqualified** or qualified class names (not fully
qualified class names) are resolved at **run-time**. ".
This describes exactly what I am expecting.
Previous Comments:
------------------------------------------------------------------------
[2014-11-24 00:51:13] requinix@php.net
There is no inheritance in the first place. "Helper::$Value" does not work as a relative
path but is merely shorthand for writing "\Alpha\Helper::$Value", and was resolved as such
at compile-time.
The feature you're trying to report a bug for *does not exist*.
------------------------------------------------------------------------
[2014-11-23 23:59:53] llmll at gmx dot de
The example shows a clear breach in namespace/inheritance logic - this qualifies as bug.
As you explain a mere c&p of the method to the new class would resolve the issue. I remeber
reading nearly the same tips here, when LSB wasn't there and people claimed __CLASS__ was
sufficient for everything and for everything else just c&p. I personally stay away from hackish
tricks, the important namespace functionality should be consistent. So my suggestion is focusing on
the problem not the alternatives.
------------------------------------------------------------------------
[2014-11-23 23:43:11] requinix@php.net
That may be but it's still not a bug. There is no such feature like what you're
describing; the closest is LSB which is why I brought it up.
Your options include
a) Beta\Base redefining Write() to use the Helper class that it wants to use.
b) (Ab)using get_called_class() to extract the called namespace, test that the corresponding Helper
class exists, and use its $Value.
c) Dependency injection, which sounds like the best solution to whatever you're trying to do.
------------------------------------------------------------------------
[2014-11-23 23:03:31] llmll at gmx dot de
Sorry to say, but you did not understand the example provided. Please go through it again and find
that it has nothing to do with late static binding.
Your suggestion is invalid. A static::$Value is not defined, as we want the $Value property of a
different class: \Alpha\Helper. So we access it as Helper::$Value.
And here comes the problem. When later both classes are inherited / copied to \Beta namespace, the
Helper::$Value readout still accesses \Alpha\Helper::$Values, but it should be using
\Beta\Helper::$Value.
------------------------------------------------------------------------
[2014-11-23 22:35:30] requinix@php.net
LSB happens with the static keyword, not class names. Classes always resolve according to the
namespace of the code being executed (or by use statements), not some kind of contextual namespace
dependent on where the code is being executed.
echo static::$Value;
Don't forget that trying to access an undefined static property will fatal.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=68485
--
Edit this bug report at https://bugs.php.net/bug.php?id=68485&edit=1
Thread (10 messages)