Skip to content

Instantly share code, notes, and snippets.

View clarkphp's full-sized avatar

Clark Everetts clarkphp

View GitHub Profile
@clarkphp
clarkphp / money-format-tests.php
Last active August 12, 2022 12:01
Scratchpad for making a map from money_format() to NumberFormatter->formatCurrency()
#!/usr/bin/env php
<?php
error_reporting(E_ALL & ~E_DEPRECATED & ~E_WARNING);
// money_format() format specification string elements
$fillChar = '(=.){0,1}';
$suppressGroupingChars = '(\^){0,1}';
$posNegFormatStyle = '(\+|\(){0,1}';
$suppressCurrencySymbol = '(!){0,1}';
$leftJustify = '(-){0,1}';
@clarkphp
clarkphp / Makefile-help-demo
Created May 16, 2021 12:44
A Makefile to illustrate display of help text
#!make
########################## Variables #####################
HERE := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
##########################################################
# I encountered this idea from my colleague Roman Basayev
.PHONY:
default: help
@clarkphp
clarkphp / git-use-main.md
Created August 15, 2020 11:01
Use default branch name of "main" instead of "master" in Git repositories

Set default branch name for new repositories to "main"

git version 2.28+

$ git config --global init.defaultBranch main

git version 2.27 or less

@clarkphp
clarkphp / php5-php7-compatible-get-last-error.md
Created May 31, 2019 22:53
PHP 5 and 7 compatible use of $php_errormsg, , error_clear_last(), and error_get_last()

Before we start

This is really short, but it saved the day, okay?

The Problem

You're migrating from PHP 5 to PHP 7 - about time, isn't it? - and you're replacing $php_errormsg with error_clear_last() and error_get_last(), but you realize the newer functions are PHP 7 only, and you can't deploy the updated code to your thousands of servers all at once, because you live in the real world.

This particular application has to run under both PHP 5 and PHP 7.

@clarkphp
clarkphp / php4-constructor-modernization.md
Last active May 22, 2019 14:34
PHP 4 Class Constructor Modernization to PHP 5+

Modernizing PHP 4 style constructors in both a forwards and backwards-compatible fashion requires two things:

  • renaming the PHP4 style constructor to __construct().
  • implementing a PHP4 style method that invokes the PHP5 __construct().

The typical fix of renaming the PHP 4 style constructor to __construct works perfectly for code that is available to be scanned and fixed.

If code over which the maintainers have no control extends any of these classes and invokes the constructors by the old method name, that extending code will break, because it will be calling a method name which no longer exists.

Before

<?php
// analyse-codebase.php
// Runs several PHP static analysis tools; assumes *.phar names
// This could be done with a shell/batch script, instead of php.
// If running under Windows, use paths like 'C:\desired\path\to\file'
// If running under *nix, use paths like '/desired/path/to/file'
// If PHP binary is not in your command path, you need to specify path to it.
// const PHP_EXE = '/the/path/to/your/PHP/executable';
@clarkphp
clarkphp / php-dependency-mgt-with-composer-setup.md
Last active October 18, 2016 15:15
Setup Instructions for Workshop "PHP Dependency Management with Composer"
@clarkphp
clarkphp / php.sh
Created February 1, 2016 09:41
Keeping Tools Up to Date
#!/usr/bin/bash
# On Windows, using Gitbash and Zend Studio PHP binary. This file not be needed for *nix with PHP truly "installed."
# Kind of lame, but I use this to run php scripts:
# $ ./php.sh update-all-my-qa-tools.php
/c/Program\ Files/Zend/Zend\ Studio\ 13.0.0/plugins/com.zend.php.debug.debugger.php56.win32_13.0.1.v20151112-2045/resources/php56/php "$@"
@clarkphp
clarkphp / keybase.md
Created March 12, 2015 17:24
Keybase Proof

Keybase proof

I hereby claim:

  • I am clarkphp on github.
  • I am clarkeveretts (https://keybase.io/clarkeveretts) on keybase.
  • I have a public key whose fingerprint is 268F 71BA E744 AF06 9A36 A95E 49F8 FF51 DFAD DFAA

To claim this, I am signing this object: