vaso123
vaso123

Reputation: 12391

PHP missing notices

here are some X-files.

Let's check this script: https://admin.laysoft.tk/test.php

We tested it on different machines with different version of PHP.

Let's see this:

$tomb = 666; 
var_dump($tomb); 
$a = $tomb['akarmi']; 
var_dump($a); 

Result of this is:

int(666) 
NULL 

($tomb means array)

As you see, we initialized the $tomb as an integer.

Why $a = $tomb['akarmi']; does not drop a notice, that no key like this?

UPDATE

I've reported it, I am so curious.

https://bugs.php.net/bug.php?id=74579

UPDATE2

Ok, this bug is exists from years. There are a lot of issue about this:

https://bugs.php.net/bug.php?id=37676

Upvotes: 4

Views: 85

Answers (1)

Narf
Narf

Reputation: 14752

Because of PHP's type juggling feature, which will implicitly convert between types, depending on how you attempt to access a variable.

The conversion to arrays however is not implemented, not even defined how it should work, as the manual says:

The behaviour of an automatic conversion to array is currently undefined.


As for why it has remained that way through the years ... nobody could really answer that question.

Upvotes: 3

Related Questions