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
@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 / benchmark.php
Created Feb 6, 2011
Compares multidimensional, flat and string access
View benchmark.php
<?php
echo '<pre>';
$w = 1000;
$h = 1000;
// generate multidimensional array
$multi = array();
for ($i = 0; $i < $w; ++$i) {
@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 evil.php
<?php
class PHPTokenizer_Tokenizer_PHP53To536 extends PHPTokenizer_Tokenizer_Base
{
public function tokenize($code) {
@$resetErrorMsg;
$tokens = @token_get_all($code);
$error = error_get_last();
try {
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 ===
@nikic
nikic / php.pecl.log
Created Dec 22, 2011
PECL discussion on SPL exceptions
View php.pecl.log
(3:22:33 PM) johannes: hey ho helly\G
(3:22:33 PM) helly\G: Moin moin
(3:24:21 PM) chregu_ [~chregu@77-58-253-248.dclient.hispeed.ch] entered the room.
(3:25:56 PM) jpauli1: helly\G: helly ! :) morning ^^
(3:26:26 PM) helly\G: Jo
(3:28:41 PM) jpauli1: helly\G: sorry that the guy (forgot his name) who wants to review ext/SPL code seems not here ATM
(3:29:19 PM) nikic: jpauli1: Levi?
(3:29:30 PM) jpauli1: nikic: +1 :)
(3:29:39 PM) helly\G: Spl use or extend?
(3:29:40 PM) jpauli1: nikic: I'm not good at names remembering :p
You can’t perform that action at this time.