Skip to content

Instantly share code, notes, and snippets.

View markkelnar's full-sized avatar

Mark Kelnar markkelnar

  • WP Engine
  • Austin, Tx
View GitHub Profile
@markkelnar
markkelnar / gist:ebc2f147ce70116991b2
Created August 6, 2014 01:23
PHP lint checker - pre commit hook
#!/bin/bash
# Put this file in .git/hooks/pre-commit
# Change it to be executable! If you don't do this, it won't work
# chmod +x .git/hooks/pre-commit
git diff-index --diff-filter=ACMR --name-only --cached HEAD |
grep '.php$' |
xargs -tn1 php -l
if (( $? )); then
@markkelnar
markkelnar / gist:4953672
Created February 14, 2013 15:49
Fun with ticks.
<?php
declare(ticks=1);
// A function called on each tick event
function tick_handler()
{
echo "tick_handler() called\n";
$trace = debug_backtrace();
if (count($trace) <= 1) {
@markkelnar
markkelnar / gist:3723638
Created September 14, 2012 18:11
PHP variable variables
<?php
# Reference http://us.php.net/language.variables.variable
class foo { static function hello() { print __LINE__." ".get_class()." world\n"; } }
class bar { function hello() { print __LINE__." ".get_class()." world\n"; } }
function hello() { print __LINE__." world\n"; }
call_user_func('hello');
call_user_func( array('foo','hello') );
@markkelnar
markkelnar / bad.php
Created June 10, 2012 04:40
bad code
<?php
$__array = array(
"g"=>"103 101 116 95 97 99 99 101 115 115",
"r"=>"82 101 115 116 114 105 99 116 101 32 97 99 99 101 115 115",
"e"=>"101 118 97 108",
"b"=>"98 97 115 101 54 52 95 100 101 99 111 100 101",
);
foreach($__array as $__key=>$__val) $__array[$__key] = implode("", array_map("chr", explode(" ", $__val)));