June 22, 2013

Careful using PHP array_merge

Using array_merge bit me today when I merged an array (which happened to be empty) with a numerically indexed array. Because the array I was merging was empty, I expected my other (numerically indexed) array to remain untouched. However that wasn’t the case, from the docs: Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array. This meant that the following array keys went from being their constant numeric values, to 0, 1, 2, 3: ... Read more

June 21, 2013

PHP ['SCRIPT_NAME'] returning empty string

I was working with Slim (v2.2.x) the other day and saw that a PHP warning was being thrown in one of the interal Slim files: Warning: strpos(): Empty needle in /vendor/slim/slim/Slim/Environment.php on line 143 The code throwing the warning was the following if statement: if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) { The actual issue was that $_SERVER['SCRIPT_NAME'] was an empty string, so strpos was complaining as that is invalid syntax. ... Read more

June 3, 2013

PHP Composer error - cannot redeclare class

I rebuilt PHP last night to include APC and all of a sudden composer stopped working in my project. Whenever I ran a simple update, install or dump-autoload I’d get: $ composer update PHP Fatal error: include(): Cannot redeclare class symfony\component\process\process in phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php on line 183 Fatal error: include(): Cannot redeclare class symfony\component\process\process in phar:///usr/local/bin/composer/vendor/composer/ClassLoader.php on line 183 A quick google told me others also had the same issue. ... Read more

June 2, 2013

Installing APC in PHP 5.4.x on Mac OSX

I recently installed PHP 5.4 from source but needed to add APC. Most people can install this using PECL, but I got an error doing this: $ pecl install apc Warning: lstat(): Lstat failed for /private/tmp/pear/cache/497e483d585c1e3f341260e73a8c6e85rest.cacheid in PEAR/REST.php on line 276 Warning: lstat(): Lstat failed for /private/tmp/pear/cache/497e483d585c1e3f341260e73a8c6e85rest.cacheid in /opt/php-5.4.15/lib/php/PEAR/REST.php on line 276 No releases available for package "pecl.php.net/apc" install failed So instead I downloaded the APC source from the PECL website and ran the following: ... Read more

May 29, 2013

Installing Xdebug on Mac Mountain Lion (10.8.3)

Even though I’m running Mountain Lion (10.8.3) which comes with Xdebug I couldn’t get the PHP (5.4.14) local web server to register that Xdebug was actually installed and enabled. My php.ini had the already installed Xdebug extension enabled: zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so" But whenever I inspected phpinfo() there wasn’t any mention of Xdebug. Luckily the website has a wizard where you can paste the output of phpinfo(). From there you get detailed instructions on how to download, configure and make the latest version of Xdebug. ... Read more

May 6, 2013

Date timezone error when upgrading to PHP 5.3+

I upgraded to 5.4.14 last night on Mac OSX 10.8.3. Things went smoothly except I got an error running my apps: date(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date. ... Read more

May 6, 2013

Installing PHP 5.4+ from source on Mac OSX Mountain Lion

Download and extract the PHP source from php.net, for me that was 5.4.14. Put it somewhere friendly, the desktop will do. Open a terminal and install some dependancies via brew: brew install libjpeg brew install pcre brew install libxml2 brew install mcrypt Download and install ICU from http://site.icu-project.org/download/48#ICU4C-Download tar xzvf icu4c-4_8_1-src.tgz cd icu/source ./runConfigureICU MacOSX make sudo make install Rebuild IMAP, download source from ftp://ftp.cac.washington.edu/imap/ make osx EXTRACFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" sudo cp c-client/*. ... Read more

May 11, 2011

Wordpress - detecting the categories of a post

I was creating a Wordpress child theme (the best way to modify/override your themes) tonight and had the need to have different display options depending on which categories the blog article had. So for example if I had a post categorised with “portfolio”, I wanted to hide the comments form which usually sits at the bottom of a post. The following snippet will loop over all post categories, if it finds that “portfolio” is one of the categories assigned to the current post then a local variable (boolean) is set which you can use to hide Wordpress functions anywhere in the current template. ... Read more

May 11, 2011

FancyBox for Wordpress plugin not working

I just spent some time figuring out why fancybox wasn’t working tonight (image thumbnails were just linking to the large image…not loading the overlay as they should). It now seems obvious after the fact but as far as I can see it’s NOT in the fancybox docs. When you insert your gallery from the media section of a page in wp-admin, you HAVE to choose “Image File”, not “Attachment Page”. That’s it! ... Read more

December 13, 2008

Development configuration tips for Ubuntu

I just setup my machine at home with Ubuntu 8.10 (desktop) which was so easy think I saved hours off the time it would normally take with Windows. So much is already installed and ready to go and with apt (or the Synaptic package manager) it’s super quick to download and install extra things things like MySQL, PHP, Apache, Java etc Here are some notes which helped me out when configuring some of these development tools. ... Read more

© Michael Sharman 2017