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
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
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
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
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’,