Skip to content

Instantly share code, notes, and snippets.

View mikeschinkel's full-sized avatar

Mike Schinkel mikeschinkel

View GitHub Profile
@mikeschinkel
mikeschinkel / form1.php
Last active May 6, 2020 21:44
Examples showing a huge array literal vs. many small array literals
<?php
class MembershipForm {
static function form() {
return array(
array(
'type' => 'textfield',
'heading' => __( 'License Type ID' ),
'param_name' => 'license_type',
'description' => esc_attr__( 'Enter License Type ID', 'wds-vc-elements' ),
@mikeschinkel
mikeschinkel / module.audio.mp3.php
Created March 16, 2020 01:35
module.audio.mp3.php from WordPress where decodeMPEGaudioHeader() is partially refactored from over 600 lines to ~200 lines.
<?php
/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org> //
// available at https://github.com/JamesHeinrich/getID3 //
// or https://www.getid3.org //
// or http://getid3.sourceforge.net //
// see readme.txt for more details //
/////////////////////////////////////////////////////////////////
// //
@mikeschinkel
mikeschinkel / ArraySorter.php
Last active March 8, 2020 22:34
A hypothetical approach for creating an object-based approach to sorting arrays in PHP
<?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
mikeschinkel / meta.php
Created February 13, 2020 03:30
A hypothetical ::meta for PHP symbols and variables that would provided a streamlined reflect
<?php
namespace Acme;
class Foo {
private const XYZ = 123;
public $bar = 'hello';
function baz():int { return 0; }
}
echo Foo::meta->type->name; // object
@mikeschinkel
mikeschinkel / import.sh
Last active January 22, 2020 06:53
Import script for Pantheon DB from mysite1.live to mysite2.live (does this work?)
#!/usr/bin/env bash
db_file="$(terminus backup:list mysite1.live | grep -m1 database.sql.gz | awk '{print $1}')"
db_url="$(terminus backup:get mckissock.live --element=db --file="${db_file}")"
terminus import:db --yes mysite2.live "${db_url}"
@mikeschinkel
mikeschinkel / !PhpProjection.md
Last active January 13, 2020 01:26
Brainstorming on a concept for PHP I am calling "Projection" here.

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
mikeschinkel / !PhpPreloading.md
Last active January 13, 2020 01:28
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

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.

SELECT name
FROM sqlite_master
where type = 'table'
# crime_scene_report
# drivers_license
# person
# facebook_event_checkin
# interview
# get_fit_now_member
@mikeschinkel
mikeschinkel / _readme.md
Last active January 24, 2023 05:47
Examples for how a __toArray() magic method could be useful in PHP.

Examples for how a __toArray() magic method could be useful in PHP.

In a nutshell, __toArray() would not be as useful when you have full control over the entire codebase.

But where __toArray() would be extremely useful is in interfacing with existing code that expects arrays and wants those arrays to be a specific format. Using classes and type-hinted methods allow to encapsulate the intelligence into the class, and using __toArray() makes for a nature use-case.

@mikeschinkel
mikeschinkel / proposal-for-union-class-types-in-php.md
Last active September 17, 2019 11:24
Proposal for Union Class Types in PHP