Skip to content

Instantly share code, notes, and snippets.

@ircmaxell
ircmaxell / php_errors.txt
Created July 27, 2011 15:50
All errors in the 5.3 source code tree (zend_error|php_error_docref)
./ext/bcmath/bcmath.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero");
./ext/bcmath/bcmath.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero");
./ext/bcmath/bcmath.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Square root of negative number");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "length may not be negative");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read valid bz2 data from stream");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode);
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "filename cannot be empty");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode);
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode);
@ircmaxell
ircmaxell / gist:1188649
Created September 2, 2011 13:57 — forked from anonymous/gist:1188637
PHP example on variable variables - without needing them
<?php
function bar($a, $b, $c) {
$r = new ReflectionFunction(__FUNCTION__);
$params = func_get_args();
$form = array();
foreach ($r->getParameters() as $param) {
$form[$param->getName()] = array(
'#type' => 'hidden',
'#value' => $params[$param->getPosition()],
@ircmaxell
ircmaxell / Expressions.php
Created September 21, 2011 16:51
A math parser and evaluator implementation
<?php
class Parenthesis extends TerminalExpression {
protected $precidence = 6;
public function operate(Stack $stack) {
}
public function getPrecidence() {
return $this->precidence;
@ircmaxell
ircmaxell / Brainfuck.php
Created September 23, 2011 13:58
Brainfuck PHP Interpreter
<?php
require_once 'Memory.php';
require_once 'Stack.php';
require_once 'Expressions.php';
class Brainfuck {
public function run($code, $input, $eof = 0) {
$memory = new Memory(array_map('ord', str_split($input)), $eof);
@ircmaxell
ircmaxell / hash_pbkdf2.patch
Created January 19, 2012 18:30
hash_pbkdf2() addition patch
Index: ext/hash/php_hash.h
===================================================================
--- ext/hash/php_hash.h (revision 322459)
+++ ext/hash/php_hash.h (working copy)
@@ -127,6 +127,7 @@
PHP_FUNCTION(hash_update_file);
PHP_FUNCTION(hash_final);
PHP_FUNCTION(hash_algos);
+PHP_FUNCTION(hash_pbkdf2);
@ircmaxell
ircmaxell / decorator.php
Created January 26, 2012 13:52
Decorator Implementation
<?php
class Ruler {
// Returns in meters
public function measure(Point $a, Point $b) {
}
}
class SAEDecorator {
protected $ruler;
@ircmaxell
ircmaxell / flyweight.php
Created February 23, 2012 14:27
Flyweight Enums
<?php
abstract class MyEnum {
private static $initialized = false;
private static $values = array();
public static function initialize() {
self::$values['MyFirstValue'] = new MyFirstValue(1);
self::$values['MySecondValue'] = new MySecondValue(2);
@ircmaxell
ircmaxell / gist:1929587
Created February 28, 2012 04:42
POC for __castTo and __assign, NOTE: UNSTABLE
Index: Zend/zend.h
===================================================================
--- Zend/zend.h (revision 322430)
+++ Zend/zend.h (working copy)
@@ -486,6 +486,8 @@
union _zend_function *__call;
union _zend_function *__callstatic;
union _zend_function *__tostring;
+ union _zend_function *__castto;
+ union _zend_function *__assign;
@ircmaxell
ircmaxell / gist:1947259
Created March 1, 2012 04:24
Scalar Casting Patch POC, version 2
Index: Zend/zend.h
===================================================================
--- Zend/zend.h (revision 322430)
+++ Zend/zend.h (working copy)
@@ -486,6 +486,11 @@
union _zend_function *__call;
union _zend_function *__callstatic;
union _zend_function *__tostring;
+ union _zend_function *__toint;
+ union _zend_function *__tofloat;
@ircmaxell
ircmaxell / gist:1955338
Created March 2, 2012 03:27
POC for type casting (same rules as internal variables)
Index: Zend/zend_execute.c
===================================================================
--- Zend/zend_execute.c (revision 322430)
+++ Zend/zend_execute.c (working copy)
@@ -646,7 +646,39 @@
return zend_verify_arg_error(E_RECOVERABLE_ERROR, zf, arg_num, "be callable", "", zend_zval_type_name(arg), "" TSRMLS_CC);
}
break;
-
+ case IS_DOUBLE: