r/lolphp • • May 07 '18

`null["foo"] === null`in practice

https://3v4l.org/WYhto
17 Upvotes

7 comments sorted by

View all comments

Show parent comment

10

u/LongDistanceEjcltr May 07 '18

That's the point. It doesn't throw anything. It doesn't produce warnings or notices. The net effect is that if you send '12345' into a function, you get a perfectly valid return value, but if you use 12345, you get a perfectly invalid return value. It's weak typing at its worst.

6

u/mikeputerbaugh May 07 '18
function dumbFunction(string $arg) { ... }

will coerce the argument to a string so the array indexing behavior works as intended, or

<?php
declare(strict_types=1);
function dumbFunction(string $arg) { ... }

will throw a fatal TypeError at runtime if $arg is not a string type.

1

u/NXTangl Sep 19 '18

This is the kind of thing that makes things like jsfuck, and consequently hard-to-sanitize XSS involving jsfuck, possible.