0

can someone explain me why this code prints true without any error or warning ?

if i use the same code without the reference on the array then if will give me false and a notice on the index not existing.

what is the difference between the two that explain such a behavior, is it a bug ?

I tested this code with php 7.0

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

$bar = [];
$foo = &$bar['key'];
echo array_key_exists("key", $bar)? "true" : "false";
Yannis Berrouag
  • 356
  • 2
  • 8

1 Answers1

2

Not a real SO answer, but:

Referring to this answer, &$bar['key'] creates the index in $bar with a value of null, because key was not present before. Now it is and true is printed.

Keep those references in mind:

BenRoob
  • 1,662
  • 5
  • 22
  • 24