Skip to content

Instantly share code, notes, and snippets.

@paulgibbs
Last active January 8, 2017 11:29
Show Gist options
  • Save paulgibbs/fe4f1e4f300837893a678a0fc52e90aa to your computer and use it in GitHub Desktop.
Save paulgibbs/fe4f1e4f300837893a678a0fc52e90aa to your computer and use it in GitHub Desktop.
weird php
<?php
$argv = array_slice( $GLOBALS['argv'], 1 );
die(var_dump(array(
$argv,
$argv[$i],
serialize($argv[$i]),
json_encode($argv[$i]),
json_decode(json_encode($argv[$i]))
)));
/*
$i = the position of the value that starts "--require". Attained via a substr comparision in a simple FOR loop.
when above run on CLI PHP as part of a WP-CLI script, it produces (via var_dump):
*/
array(5) {
[0] =>
array(6) {
[0] =>
string(8) "@vagrant"
[1] =>
string(7) "--debug"
[2] =>
string(10) "--no-color"
[3] =>
string(87) "--require=src/WpcliLogger.php"
[4] =>
string(3) "cli"
[5] =>
string(7) "version"
}
[1] =>
string(87) "--require=src/WpcliLogger.php"
[2] =>
string(95) "s:87:"--require=src/WpcliLogger.php";"
[3] =>
string(96) ""--require=\/Users\/paulgibbs\/Sites\/behat-vm\/behat-wordpress-extension\/src\/WpcliLogger.php""
[4] =>
string(87) "--require=src/WpcliLogger.php"
}
@paulgibbs
Copy link
Author

paulgibbs commented Jan 8, 2017

I am expecting output [1] to be the same as [3] (without the JSON formatting obviously). Note [1]'s character length given by var_dump -- 87 -- suggests the internal value is more than what's showing me. [3], the json_encoded version, shows the entire value, but even when I subsequently call json_decode, I still get back this abridged value.

I suspect it's something to do with touching $GLOBALS['argv'], which I've never really done before, but I'm pretty baffled.
This was run inside a VM running PHP 5.6.17.

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