Skip to content

Instantly share code, notes, and snippets.


Mike Schinkel mikeschinkel

View GitHub Profile
mikeschinkel / 1.attributes-with-use.php
Last active Aug 18, 2020
Hypothetical example of using use statement for attributes
View 1.attributes-with-use.php
namespace MyNamespace;
// namespace use
use WpAttributes\PrimaryKey;
use WpAttributes\PostType;
use WpAttributes\TemplateVariable;
use PHP\VirtualReadonly;
mikeschinkel /
Last active May 17, 2020
Refactoring Pantheon_Sessions::initialize_session_override() using do{...}while(false);

Example use of do {...} while(false)

See this gist for background.

This example comes from my work here when looking for a solution for this issue related to this WordPress plugin.

I recognized I could make it clearer using the do {...} while(false) pattern so I wanted to document here.


mikeschinkel / Apis.php
Last active May 14, 2020
PHP Examples that could benefit from Try...Break (method excerpts from real production code)
View Apis.php
class Apis {
static function JsonGET( string $api_url, array $args = array() ) {
do {
$wp_error = null;
$args = wp_parse_args( $args, array(
'response_type' => ARRAY_A,
) );
mikeschinkel / form1.php
Last active May 6, 2020
Examples showing a huge array literal vs. many small array literals
View form1.php
class MembershipForm {
static function form() {
return array(
'type' => 'textfield',
'heading' => __( 'License Type ID' ),
'param_name' => 'license_type',
'description' => esc_attr__( 'Enter License Type ID', 'wds-vc-elements' ),
mikeschinkel /
Created Mar 16, 2020 from WordPress where decodeMPEGaudioHeader() is partially refactored from over 600 lines to ~200 lines.
/// getID3() by James Heinrich <> //
// available at //
// or //
// or //
// see readme.txt for more details //
// //
mikeschinkel / ArraySorter.php
Last active Mar 8, 2020
A hypothetical approach for creating an object-based approach to sorting arrays in PHP
View ArraySorter.php
* One option is to create `PHP` as a reserved namespace for extensions
* that do not have to be backward compatible from the initial creation
* backwards, except of course for those who may have previously created
* their own PHP namespace.
* I've tried to implement warnings and errors, but they are not exhaustive
* and some more could be added if this had a real chance to make it into
* PHP core.
mikeschinkel / meta.php
Created Feb 13, 2020
A hypothetical ::meta for PHP symbols and variables that would provided a streamlined reflect
View meta.php
namespace Acme;
class Foo {
private const XYZ = 123;
public $bar = 'hello';
function baz():int { return 0; }
echo Foo::meta->type->name; // object
mikeschinkel /
Last active Jan 22, 2020
Import script for Pantheon DB from to (does this work?)
#!/usr/bin/env bash
db_file="$(terminus backup:list | grep -m1 database.sql.gz | awk '{print $1}')"
db_url="$(terminus backup:get --element=db --file="${db_file}")"
terminus import:db --yes "${db_url}"
mikeschinkel / !
Last active Jan 13, 2020
Brainstorming on a concept for PHP I am calling "Projection" here.
View !

Brainstorming on a concept for PHP I am calling "Projection" here. This could be a new API for PHP or just extensions to Reflection.

The examples below are far from complete and I am sure there are missing aspects in some of these interfaces as this is just an exploration of concept and not something fully tested.

Note that I used leading underscores on file names to order which files are displayed by Gist above the other files, except for _Class, _Interface and _Trait which have leading underscores to

mikeschinkel / !
Last active Jan 13, 2020
Simple config class in PHP illustrating how a `preload` might work. In this example, the load() method uses the `preload` modifier on Line 38 of config.php
View !

Since Config::load() is declared with preload (which should imply static) it would be run once and its return value would be converted to OpCode so when the following line of code runs during normal execution — such as on the web for each page load — it would execute extremely fast and would not open nor decode the config.json file, since that would have been done a OpCode generation time.

You can’t perform that action at this time.