Skip to content

Instantly share code, notes, and snippets.

View nikic's full-sized avatar
🌴
On vacation

Nikita Popov nikic

🌴
On vacation
View GitHub Profile
@nikic
nikic / demo.php
Created December 26, 2016 20:54
Demo for format preserving AST transformation
<?php
/* This demo replaces all unqualified function calls and namespaced lookups
* with fully qualified ones. Apart from this change all formatting should
* be preserved. */
use PhpParser\Lexer;
use PhpParser\Parser;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
JIT$$interrupt_handler: ; (unknown)
mov $0x0, EG(vm_interrupt)
cmp $0x0, EG(timed_out)
jz .L1
xor %edi, %edi
call zend_timeout
.L1:
add $0x8, %rsp
jmp (%r15)
diff --git a/ext/date/lib/parse_tz.c b/ext/date/lib/parse_tz.c
index 308437e..ebc4d1e 100644
--- a/ext/date/lib/parse_tz.c
+++ b/ext/date/lib/parse_tz.c
@@ -438,7 +438,7 @@ static struct location_info **create_location_table(void)
return NULL;
}
- li = timelib_calloc(LOCINFO_HASH_SIZE, sizeof *li);
+ li = calloc(LOCINFO_HASH_SIZE, sizeof *li);
<?php error_reporting(E_ALL);
function formatT($t) {
return sprintf('%.1f mus', $t * 1000000);
}
function formatResult($result) {
list($mean, $stddev) = $result;
return formatT($mean) . " +/- " . formatT($stddev);
}
@nikic
nikic / BinaryTree.php
Created April 23, 2015 12:16
Tree traversal performance: yield from vs. naive implementation
<?php error_reporting(E_ALL);
class BinaryTree {
private $content, $left, $right;
public function __construct($content, BinaryTree $left = null, BinaryTree $right = null) {
$this->content = $content;
$this->left = $left;
$this->right = $right;
}
<?php
require './vendor/autoload.php';
// The code samples to parse.
// => bool(false)
$code = '<?php class Foo {public $bar;}';
// => bool(true)
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,
@nikic
nikic / portAlternativeTags.php
Created September 12, 2014 17:41
Tool for porting alternative PHP tags to <?php, <?= and ?>
<?php
/*
* Note: This script will directly modify the .php files in the given directory.
* It is assumed that the code is under version control, so you can easily review
* the changes using `git diff` or similar.
*/
function usageError() {
die("Usage: php -d asp_tags=1 portAlternativeTags.php dir/\n");
@nikic
nikic / benchCompiler.php
Last active October 28, 2021 07:57
Scripts for measuring compile time
<?php ini_set('memory_limit', -1);
if ($argc != 3) die("error\n");
$file = $argv[1];
$num = $argv[2];
$startTime = microtime(true);
for ($i = 0; $i < $num; ++$i) {
require $file;
@nikic
nikic / varVar.php
Created June 9, 2014 14:11
Script for finding variable-variable usages potentially affected by uniform variable syntax
<?php
use PhpParser\Node;
use PhpParser\Node\Expr;
error_reporting(E_ALL);
ini_set('memory_limit', -1);
//$dir = __DIR__ . '/../../Symfony_2.3';