Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Last active June 15, 2018 09:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeoncross/049a1c4ba19d0120d754c8e6141b759b to your computer and use it in GitHub Desktop.
Save xeoncross/049a1c4ba19d0120d754c8e6141b759b to your computer and use it in GitHub Desktop.
One of the great things about PHP is you don't have the follow the rules when hacking stuff together. This makes map-building work easy to type up. However, since Golang there isn't much reason to use PHP anymore. Golang exceeds in every area from the stdlib to the speed and security of the application.
<?php
// Type casting is easy on weak languages
$a = (object) (array) (object) (array) (object) ["foo" => "bar"];
// PHP will happily iterate over an object (like Javascript)
foreach($a as $key => $value) {
print "$key = $value" . PHP_EOL;
}
$foo = "foo";
$b = (array) $a;
// Variable variable access - even inside a string!
print $a->$$foo . " = {$a->$foo} = $b[$foo]" . PHP_EOL;
// Look at this Golang! No need for a new variable to prevent confusion!
$a = ['foo' => [1,2,3]];
// More variable variables
$alias = "a";
${$alias}[$foo][] = 4;
// Look a temp function result is functioning as a variable variable!
${chr(97)}[$foo][] = 5;
print_r($a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment