Skip to content

Instantly share code, notes, and snippets.

@bagart
Last active November 9, 2018 22:36
Show Gist options
  • Save bagart/60ed34f9e851a2b9e16a3f92e83e2f33 to your computer and use it in GitHub Desktop.
Save bagart/60ed34f9e851a2b9e16a3f92e83e2f33 to your computer and use it in GitHub Desktop.
array with double key
<?php
class A {
private $omg = 'A';
function dump() {
return get_object_vars($this);
}
}
class B extends A {
public $omg = 'B';
}
var_dump((new B())->dump());
$q = (new B())->dump();
var_dump([
'is_array' => is_array($q),
'is_object' => is_object($q),
'dump' => $q,
'dump+' => $q + ['omg'=>1],
'+dump' => ['omg'=>1] + $q
]);
var_dump([
'0 curr ' . current($q) => $x0 = key($q),
'1 next ' . next($q) => $x1 = key($q),
'2 prev ' . prev($q) => $x2 = key($q),
"0 === 1" => $x0 === $x1,
"0 === 2" => $x0 === $x2,
]);
@bagart
Copy link
Author

bagart commented Nov 9, 2018

PHP 7.0 - 7.1 - 7.2 - 7.3RC

array(2) {
  ["omg"]=>
  string(1) "B"
  ["omg"]=>
  string(1) "A"
}
array(5) {
  ["is_array"]=>
  bool(true)
  ["is_object"]=>
  bool(false)
  ["dump"]=>
  array(2) {
    ["omg"]=>
    string(1) "B"
    ["omg"]=>
    string(1) "A"
  }
  ["dump+"]=>
  array(2) {
    ["omg"]=>
    string(1) "B"
    ["omg"]=>
    string(1) "A"
  }
  ["+dump"]=>
  array(1) {
    ["omg"]=>
    int(1)
  }
}
array(5) {
  ["0 curr B"]=>
  string(3) "omg"
  ["1 next A"]=>
  string(3) "omg"
  ["2 prev B"]=>
  string(3) "omg"
  ["0 === 1"]=>
  bool(true)
  ["0 === 2"]=>
  bool(true)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment