Hi!

> In that case, __get() would not be called, since the property is defined
> on the class, just not in a traditional way.  This behavior is not
> unprecedented however, as implicitly created public properties follow the
> same pattern:

The code doing it is actually pretty explicit - you can see the variable
being assigned. In this case, however, there's no code creating them,
and still they come to exist, magically created from nowhere.

> So the observed behavior from the Child class would have the same result
> either way. They invoked the parent::__construct() after setting $this->f,
> and that constructor overrode their property set.

Again, now the overwrite is always explicit. Having implicit code that
overrides stuff may be source of very hard to track errors - since you
can not see this code, can not debug it, can not trace it - you just see
your variables magically change. I'm not sure saving one short line of
code really worth it.

Another example:

class Base { function __construct(public $a = 1) {} }
class Child { public $a = 2; }
$c = new Child();

As far as I understand here $c->a would be 1?

>> 3. What happens if I need to have some arguments that are not properties?
> 
> You do that. The following syntax is pefectly valid:
> 
> class Foo {
> public function __construct(public $f, $g) {
> // $this->f implicitly set to $f
> echo "The second arg to the constructor was $g";
> }
> }

OK, that makes sense, but mixing it in one def makes rather hard to
figure out which variables are magic and which are not. And the fact
that it'd be only context in which word "public" actually generates code
doesn't help too much.

> You wouldn't have individual Doc Comments per property, but an editor
> could parse __construct's Doc Comment. This is arguably more work for the
> IDE and/or PhpDoc generator, but the data is still there.

That means these properties don't work with Reflection like others, so
tools relying on Reflection to extract doc blocks would not work.

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to