Skip to content

Instantly share code, notes, and snippets.

<?php
spl_autoload_register(function ($name) {
// $exp will be the name of the class without the \with\traitname part => array_splice
$exp = explode("\\", $name);
// serach from end
$index = array_search("with", array_reverse($exp, true));
if (!$index || $index - 1 == count($exp)) // also fail when value is 0
return false;
@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++;
@krakjoe
krakjoe / pthreads.md
Last active August 30, 2023 18:30
pthreads.md

Multi-Threading in PHP with pthreads

A Brief Introduction to Multi-Threading in PHP

  • Foreword
  • Execution
  • Sharing
  • Synchronization
  • Pitfalls
@krakjoe
krakjoe / php_api.h
Last active December 15, 2015 18:38
a (completely untested) unified php api, perhaps, just the "gist" ... its correct "enough" ...
/* +----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |