Skip to content

Instantly share code, notes, and snippets.

Nikita Popov nikic

Block or report user

Report or block nikic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View compress.php
<?php
use PhpParser\Node;
$IN_DIR = __DIR__ . '/in_dir';
$OUT_FILE = __DIR__ . '/out_file.php';
require __DIR__ . '/../lib/bootstrap.php';
class CompressVisitor extends PhpParser\NodeVisitorAbstract {
View coalesce.diff
diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h
index 2a1582c..b571ee1 100644
--- a/Zend/zend_ast.h
+++ b/Zend/zend_ast.h
@@ -115,6 +115,7 @@ enum _zend_ast_kind {
ZEND_AST_NEW,
ZEND_AST_INSTANCEOF,
ZEND_AST_YIELD,
+ ZEND_AST_COALESCE,
View gist:04fce01e69ae5b7b44f8
<?php
require './vendor/autoload.php';
// The code samples to parse.
// => bool(false)
$code = '<?php class Foo {public $bar;}';
// => bool(true)
@nikic
nikic / RouterGenerator.php
Created Jan 17, 2011
Generates Router classes
View RouterGenerator.php
<?php
class RouteCompilationException extends LogicException
{
public function setContext($line, $route) {
$this->message = 'Line ' . $line . ': ' . $this->getMessage() . ' (route: "' . $route . '")';
}
}
class RouterCompiler
{
@nikic
nikic / A_WARNING.md
Last active Sep 25, 2015
PHP Sandbox
View A_WARNING.md

I do not recommend to use this code as it has known vulnerabilities. You may want to have a look at some more recent sandboxing project like https://github.com/fieryprophet/php-sandbox (though I can't say anything about its quality). In general though the only really safe way to sandbox PHP is to run it in a jail.

@nikic
nikic / hq9.php
Created Jun 13, 2011
HQ9 interpreter
View hq9.php
<?php
define('SAFE_MODE', 42);
echo '<pre>';
function throw_exception($error) {
die('--- EXCEPTION: ' . $error);
}
if (!isset($_GET['source'])) {
@nikic
nikic / gist:1188670
Created Sep 2, 2011 — forked from ircmaxell/gist:1188649
PHP example on variable variables - without needing them
View gist:1188670
<?php
function bar($a, $b, $c) {
foreach (compact('a', 'b', 'c') as $key => $value) {
$form[$key] = array(
'#type' => 'hidden',
'#value' => $value,
);
}
}
View md5_file_test.patch
Index: ext/standard/tests/strings/md5_file.phpt
===================================================================
--- ext/standard/tests/strings/md5_file.phpt (revision 316568)
+++ ext/standard/tests/strings/md5_file.phpt (working copy)
@@ -56,7 +56,7 @@
/* Raw Binary Output for Empty file as input */
echo "\n*** Raw Binary Output for Empty file as Argument ***\n";
-var_dump( md5_file("EmptyFile.txt", true) );
+var_dump( bin2hex(md5_file("EmptyFile.txt", true)) );
@nikic
nikic / diff.patch
Created Dec 9, 2011
Additional token_get_all param
View diff.patch
diff --git a/ext/tokenizer/tests/token_get_all_error.phpt b/ext/tokenizer/tests/token_get_all_error.phpt
index 29e97c3..5b455e9 100644
--- a/ext/tokenizer/tests/token_get_all_error.phpt
+++ b/ext/tokenizer/tests/token_get_all_error.phpt
@@ -19,7 +19,7 @@ var_dump( token_get_all());
echo "-- Testing token_get_all() function with more than expected no. of arguments --\n";
$source = '<?php ?>';
$extra_arg = 10;
-var_dump( token_get_all($source, $extra_arg));
+var_dump( token_get_all($source, false, $extra_arg));
View gist:1506556
[Wed Dec 21 17:06:58 2011] Script: 'test2.php'
/home/nikic/dev/php-src-git/Zend/zend_API.c(311) : Freeing 0xB78B836C (20 bytes), script=test2.php
Last leak repeated 1 time
[Wed Dec 21 17:06:58 2011] Script: 'test2.php'
/home/nikic/dev/php-src-git/Zend/zend_execute_API.c(876) : Freeing 0xB78B8490 (20 bytes), script=test2.php
=== Total 3 memory leaks detected ===
You can’t perform that action at this time.