Skip to content

Instantly share code, notes, and snippets.

View bragle's full-sized avatar
🧃

Leo Toneff bragle

🧃
View GitHub Profile
@bragle
bragle / example.php
Created June 23, 2019 11:38
A singleton class loader. Will convert static calls to nonstatic calls and construct the class only when needed. Use this with caution, as it may make your code less readable.
<?php
# before
DB::getInstance()->query('sql');
# after
DB::query('sql');
# Notice: All functions in the extended class must be protected.
@bragle
bragle / sanitize-with-breakpoint.php
Created May 11, 2019 22:53
Sanitize multi dimensional PHP arrays
<?php
// Only the first parameter is necessary. The other two are there because of the recursion :)
function sanitizeArray (array $array, array &$output = [], $breakpoint = 0) {
foreach($array as $key => $val){
if(++$breakpoint > 1000){
return false;