Skip to content

Instantly share code, notes, and snippets.

@sgolemon
Created October 16, 2015 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgolemon/f65fafadd90ed26f05be to your computer and use it in GitHub Desktop.
Save sgolemon/f65fafadd90ed26f05be to your computer and use it in GitHub Desktop.
My AstKit experimental branch. This is runkit levels of bad...
--TEST--
Graft new value onto a statement list
--FILE--
<?php
include('astkit-test.inc');
$if = AstKit::parseString(<<<EOD
if (true) {
echo "This is a triumph.\n";
} else {
echo "The cake is a lie.\n";
}
EOD
);
$if->execute(); // First run, program is as-seen above
$const = $if->getChild(0)->getChild(0);
// Replace the "true" constant in the condition with false
$const->graft(0, false);
// Can also graft other AstKit nodes, instead of constants
$if->execute(); / Second run now takes the else path
--EXPECT--
This is a triumph.
The cake is a lie.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment