Skip to content

Instantly share code, notes, and snippets.

View nikic's full-sized avatar

Nikita Popov nikic

View GitHub Profile
<?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 {
@nikic
nikic / routing_bench.php
Created February 17, 2014 11:46
Microbenchmark between Pux and FastRoute
<?php
error_reporting(E_ALL);
require __DIR__ . '/FastRoute/src/bootstrap.php';
spl_autoload_register(function ($class) {
require __DIR__ . '/Pux/src/' . strtr($class, '\\', '/') . '.php';
});
~^(?|/a/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)|/b/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()|/c/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()|/d/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()|/e/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()|/f/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()|/g/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()()|/h/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()()()|/i/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()()()()|/j/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()()()()()|/k/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()()()()()()|/l/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)()()()()()
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 25a604c..4dba71b 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1737,7 +1737,6 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
zend_op dummy_opline;
dummy_opline.result_type = IS_UNUSED;
- dummy_opline.op1_type = IS_UNUSED;
@nikic
nikic / php_evaluation_order.md
Last active October 19, 2021 05:47
Analysis of some weird evaluation order in PHP

Order of evaluation in PHP

Yesterday I found some people on my [favorite reddit][lolphp] wonder about the output of the following code:

<?php

$a = 1;
$c = $a + $a++;
@nikic
nikic / zts.diff
Last active December 23, 2015 01:49
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 63ecbe4..c79a551 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -94,7 +94,7 @@ static zend_always_inline void zend_pzval_unlock_free_func(zval *z TSRMLS_DC)
}
#undef zval_ptr_dtor
-#define zval_ptr_dtor(pzv) i_zval_ptr_dtor(*(pzv) ZEND_FILE_LINE_CC)
+#define zval_ptr_dtor(pzv) i_zval_ptr_dtor(*(pzv) ZEND_FILE_LINE_CC TSRMLS_CC)
@nikic
nikic / bench.php
Last active December 22, 2015 01:39
Benchmark for returning large arrays via return_value_ptr
<?php
$numElements = 10000000;
// Test end() performance
$array = [array_fill(0, $numElements, null)];
$startTime = microtime(true);
$return = end($array);
@nikic
nikic / bench.php
Last active November 2, 2023 22:49
Benchmark of call_user_func_array vs switch optimization vs argument unpacking syntax
<?php error_reporting(E_ALL);
function test() {}
$nIter = 1000000;
$argNums = [0, 1, 2, 3, 4, 5, 100];
$func = 'test';
foreach ($argNums as $argNum) {
@nikic
nikic / php-5.5-features.md
Last active August 31, 2020 10:39
List of new features in PHP 5.5