Quick tip to access protected properties in PHP object

May 27, 2020

Calling an object that has a protected property that you need access to? This function will allow you to quickly access data stored in protected properties of PHP objects. Note: I tested this on PHP 7.4. It will likely work on other versions, but may need tweaking. Good developers will protect the internals of their

Quick recursive PHP file syntax check

May 10, 2016

I find it handy to run a PHP syntax (lint) check on files after resolving a merge conflict in git. Here is a handy snippet that will run find every file in the current and sub-directories and run them through the PHP command line syntax checker. find . -iname “*.php” -exec php -l {} \;

Getting social media shares with php

October 9, 2015

Quick snippets to help me (and maybe you!) remember how to quickly and easily get share counts from social networks. What other networks would you like to see? Facebook [php] function facebook_share_count( $post_id ) { $api = "https://graph.facebook.com/"; $url = $api . urlencode( get_permalink( $post_id ) ); $response = wp_remote_get( $url ); if( is_wp_error( $response

Book Review: PHPUnit Essentials

September 1, 2014

In the past few years I have worked on many projects that involved implementing a testing infrastructure, I have spoken at conferences on the important of and theories of testing, and I have led workshops training beginners in testing. In all that time I have looked for a good concise and easy to read resource

PHP: Erase a value out of an array without knowing its key

December 9, 2013

If you find yourself with an array that you know contains a certain value that you need to access or erase here is a useful code snippet that I came across the other day. $key = array_search( $needle, $haystack ); unset( $haystack[$key] ); For example, given the following array: $colors = array( ‘red’, ‘blue’, ‘green’,