Skip to content

Instantly share code, notes, and snippets.

@kler
kler / null-is-overwritable.php
Created October 2, 2012 15:38
NULL is overwritable (scalars are not)
<?php
// Conclusion: NULL is in this case considered to be of no value, and PHP
// thinks that it is OK to overwrite, but integers are not treated the same
// This code will assign NULL and the ignore that NULL was assigned and create a stdClass:
$a = NULL;
$a->test = "apa"; // should warn in my oppinion
print_r($a);
@kler
kler / null-and-unset-are-unpredictable.php
Created October 2, 2012 15:39
NULL and unset has unpredictable behavior
<?php
// Conclusion: NULL and unset have unpredictable behavior
// === NULL are in some cases same as unset ===
// This code will assign a value, then assign NULL, and the result will show that
// PHP think this is same as unset()
$a = "test";
$a = NULL// will be same as unset()
echo (isset($a) ? "true" : "false") . "\n";
@kler
kler / semi-static-context.php
Created October 2, 2012 15:40
It is possible to call functions from a static context
<?php
class SemiStaticClass {
public function echoWhoIAm() {
echo 'I\'m ' . __FUNCTION__ . ' in class ' . __CLASS__;
// If this doesn't exists, then this function is statically called
if (! isset($this)) {
echo '... and I\'m statically called! Nice!';
}
echo "\n";
}
@kler
kler / nested_restyresolver.py
Created April 17, 2017 14:19
Proposal for restyResolver to handle nested paths
import logging
import re
from connexion.resolver import RestyResolver
logger = logging.getLogger('connexion.resolver')
class NestedRestyResolver(RestyResolver):
"""Overrider RestyResolver to support complex paths (/a/b/c/ => a.b.c)"""
@kler
kler / circular-references-segfault.php
Created October 2, 2012 15:39
Circular references may cause segmentation fault
<?php
// Conclusion: This code will cause Segmentation fault, because
// of recursive calls to __clone(), but PHP should handle this.
// Bug filed here: http://bugs.php.net/bug.php?id=49664
date_default_timezone_set('America/Los_Angeles');
class Test {
public $previous, $next = NULL;