Last active
January 8, 2017 11:29
-
-
Save paulgibbs/fe4f1e4f300837893a678a0fc52e90aa to your computer and use it in GitHub Desktop.
weird php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am expecting output
[1]
to be the same as[3]
(without the JSON formatting obviously). Note[1]
's character length given byvar_dump
-- 87 -- suggests the internal value is more than what's showing me.[3]
, thejson_encode
d version, shows the entire value, but even when I subsequently calljson_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.