Re: Typed properties problems
| From: | Rasmus Schultz | Date: | Tue, 17 Jan 2017 21:42:48 +0000 |
| Subject: | Re: Typed properties problems | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-97835@lists.php.net to get a copy of this message | ||
On regular PHP 7, the array weirdness (Dmitry's last example) doesn't even
produce a warning:
class Shit {
public $yo = false;
}
$shit = new Shit();
$shit->yo[] = "what"; // quitly turns $yo into an array!
echo gettype($shit->yo); // array
That's pretty messed-up right there. At least in the object cases there's
an E_WARNING "Creating default object from empty value" - with the array
case, nothing, it just converts your boolean into an array. Yiiiiikes.
On Tue, Jan 17, 2017 at 11:03 AM, Dmitry Stogov <dmitry@zend.com> wrote:
> Hi Bob,
>
>
> I've found a number of problems:
>
>
> $ sapi/cli/php -r 'class Foo {public bool $b = false;} $x = new Foo;
> $x->b->ops += 5; echo gettype($x->b),"\n";'
>
> object
>
> $ sapi/cli/php -r 'class Foo {public bool $b = false;} $x = new Foo;
> $x->b->ops++; echo gettype($x->b),"\n";'
> object
>
> $ sapi/cli/php -r 'class Foo {public bool $b = false;} $x = new Foo;
> $x->b->ops = 5; echo gettype($x->b),"\n";'
> object
>
> $ sapi/cli/php -r 'class Foo {public bool $b = false;} $x = new Foo;
> $x->b[] = 5; echo gettype($x->b),"\n";'
> array
>
> Thanks. Dmitry.
>
>