Zend PHP 5.3 Certification

As of last week I am officially a Zend Certified Engineer (proof) and thought I should post something on preparing for the exam and share some useful resources for others who may be working towards the 5.3 certification.

The “Zend PHP 5.3 Study Guide” which is given in .pdf (only an older PHP 5 version of the guide is available in print) from Zend when applying for the exam is not a lot of help other than to give a skeleton for study of most of the topics which will appear in the exam. The guide is by no means exhaustive on any topic (and makes a point of stating this itself) and there do seem to be a few gaps which I assume are supposed to be made up naturally with experience in working with the language and more generally with web technologies, I can’t really say more here due to Zend’s non-disclosure clause. But it is important to note which areas will have a higher weighting in the exam and ensure that these areas are covered ruthlessly during your study.

A colleague pointed me to a very useful slideshare presentation by Lorna Mitchell which (as well as having some Hitchhikers Guide comedy) lays out many of the topics for the exam along with plenty of links to further reading.

I highly recommend reading “Essential PHP Security” by Chris Shiflett from O’Reilly (regardless of studying for the exam or not), a concise book which really hammers home the need to filter and escape, covers settings with security implications and details the common web application attack types and respective defence techniques.

Another great book for the exam (and generally for non-beginners) is Sitepoint‘s “PHP Master: Write Cutting Edge Code” by Davey Shafik, Lorna Mitchell (again) and Matthew Turland. This book is meant for coders whom already possess a fair overall knowledge of PHP and builds on this with more advanced topics with lots of good code to tear away and play with yourself. Most of the book (with the exception of the chapters dealing with automated testing and QA) is very applicable to the Zend Certification.

The PHP Manual is of course an indispensable resource for all PHP’ers, and should be used with any other resource to give more depth to the topic you are studying. Make sure to cover all of the common string and array functions, as well as exploring SPL (ensuring that you actually try to implement and understand the interfaces and iterators).

Some other useful links:

Generally speaking, anyone entering the exam should bear in mind that the best asset to ensure a good chance of passing is that of experience, the more you have in using PHP to create real solutions the less gaps in your knowledge will need to be filled or re-enforced through study. Learn by doing.

As an aside, passing the exam also gets you a perpetual licence for Zend Studio which I have now begun playing with and am finding to be pretty darn clever (although it is a ‘lil resource heavy for an IDE). My previous main IDE was Rapid PHP, which may not be so feature rich but is very light (and cheap) for what you get.

Posted in glowingminds.co.uk | Tagged PHP, Zend | Leave a comment

Improve Your Form Usability with CAPTCHA Alternatives – OnlineRetailingBlog.com

I have written a new post over on The Online Retailing Blog on the topic of alternatives to standard text CAPTCHA solutions.

Posted in onlineretailingblog.com | Tagged CAPTCHA, forms | Leave a comment

PHP Error Handling – Part One, Error Types & Exceptions

As a study aid whilst working towards Zend Certification and also due to a post on the topic being requested by a colleague (Barry) and after a rant by me after a talk at PHP UK 2012, here is the first of three posts on errors in PHP.

While most languages have just one or a few ways of reporting errors, PHP has many. This can make the whole process of handling errors seem confusing or even broken, but in fact this abundance can allow for some very specific error reporting.

This post will attempt to describe PHP’s error types and exception throwing simply and give examples of how they can be generated at runtime. This example code will then form a series of tests for the standard and custom error reporting functionality which will form the topics of part two and three in this series on errors. This should help ensure that we handle every error type as well as uncaught exceptions.

The Error Types

There are three effective levels of error type in PHP:

  • Error – A non-recoverable error, execution should always be stopped, these are E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR and E_USER_ERROR.
  • Warning – A recoverable error, these are E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING and E_USER_WARNING
  • Notice – An error has occurred, which may not affect execution, these are E_NOTICE, E_USER_NOTICE, E_STRICT, E_DEPRECATED and E_USER_DEPRECATED

The error type E_RECOVERABLE_ERROR introduced in PHP 5.3 represent errors which are fatal (E_ERROR) if not handled by a custom error handler.

Additionally there is also E_PARSE which is a compile-time error and should only come from the parser, usually this type of error can be avoided all together by using a syntax checker for PHP in an editor / IDE.

One of the most used predefined error constants is E_ALL, this is not an error type in itself but represents all of the other error types in aggregate (except E_STRICT before PHP 5.4). This constant is commonly used with the standard error reporting functions which we will see in part two.

As well as the errors being of different severity the error types within each level can give an indication of why the error occured. Core errors occur in the PHP core and compile errors in the Zend engine, these should never really occur in day-to-day use (I cannot recall ever having encountered them). The E_USER_* error family are generated at run time using the trigger_error function by the user, with the message accompanied with one of the user error types. Deprecated errors (since PHP 5.3) are notifications of features which are being phased out of PHP and are unlikely to appear in later releases.

A note on bitwise operators: When setting PHP’s error_reporting directive (covered in part two) error types can be combined / ommitted using bitwise operators (the integer values for all of the error types are factors of two), this is how the E_ALL type (with a value of 32767) manages to encompass all of the other error types. You can read more about bitwise operators and error constants here.

It is also worth noting that in PHP there is an Error Control Operator, which is ‘@’. When any expression is prepended with the operator, errors in the expression will be ignored, that is not to say that script execution will continue however, fatal errors will still kill execution but you will not be told why. Generally speaking this operator should be avoided unless you are wanting to check for / handle any errors yourself (so that perhaps you could use some kind of fallback for example).

Here are all of the error types, with their predefined constant name, integer value and example of how they can be caused (where appropriate). This code can be included in any project, with each error example being uncommented to test a particular error types’ handling.

Exceptions

PHP has come a long way since it’s ‘Personal Home Page’ days and has expanded into the world of Object Orientated Programming (OOP) and with this has come exceptions. In OOP when an error occurs an exception is ‘thrown’, this should occur within a try block of code which will then be ‘caught’ by a corresponding catch block. Execution at the point of error stops and continues within the catch block, if try / catch blocks are not implemented than this can lead to OOP code throwing an ‘uncaught’ exception, we will need to implement handling of these.

Below is an example code which could cause an uncaught exception as well as a well formed try / catch block, which will handle any exception thrown in the try block in the corresponding catch block .

Note: I may well come back to this post to add more information while working on parts two and three if anything pertinent arises. Feel free to comment if there is anything which you feel should be added / fixed.

References / Further Reading:

Posted in code | Tagged Error Handling, Exceptions, PHP | Leave a comment

PuTTY Windows Registry Values Import / Export

PuTTY the ubiquitous SSH / Telnet client is in fact so lightweight that it does not even have a configuration file, an annoyance when you find yourself setting up connection details to the same servers for the nth time.

However a simple export / merge of registry values can allow you to transfer your settings between machines. The registry location in question (named after PuTTY’s original developer) is:

HKEY_CURRENT_USER\Software\SimonTatham

Simply use regedit.exe to export this location to a .reg file which can then be merged with the registry on any other Windows box.

Posted in tools | Tagged PuTTY, SSH, Windows | Leave a comment

Facebook Likes, Twitter Follows and Feedburner Count in PHP with cURL/SimpleXML (Deluxe)

So API’s from common providers are unreliable… below is the same code as my previous post but with two layers (1h + 24h) of Alternative PHP Cache (APC) caching and exception handling for the SimpleXML. Worth noting that the code expects there to be a defined non-fatal error function.

Note: PHP must be compiled with cURL: http://uk.php.net/manual/en/curl.installation.php

Note: APC must be installed with PECL: http://www.php.net/manual/en/apc.installation.php

Note: For the Feedburner API request to work you must have FeedCount activated in FeedBurner

References:

Posted in code | Tagged APC, API, cURL, Facebook, FeedBurner, PHP, SimpleXML, Twitter, XML | Leave a comment

TortoiseSVN Update and Commit Windows Batch Files

I was getting annoyed with having to use Win shell extensions to update and commit, assuming the standard install path for Tortoise, the following two snippets saved as .bat files, can be added to startup / shutdown or just used as shortcuts to make the process a bit quicker.

Commit:

Update:

References:

Posted in code | Tagged Batch Files, SVN, TortoiseSVN, Windows | 2 Comments

Facebook Likes, Twitter Follows and Feedburner Count in PHP with cURL/SimpleXML

Basic (no error handling) copy and paste code for getting Facebook Likes, Twitter Follows and a Feedburner Subscription count using PHP (with cURL):

Note: PHP must be compiled with cURL: http://uk.php.net/manual/en/curl.installation.php

Note: For the Feedburner API request to work you must have FeedCount activated in FeedBurner

References:

Posted in code | Tagged API, cURL, Facebook, FeedBurner, PHP, SimpleXML, Twitter, XML | Leave a comment

And then there was WordPress…

Welcome to the latest version (I’ve lost count of how many there have been) of this website which is now using the WordPress CMS. Will be adding some content soonish including a couple of references and online tools which are primarily for my own benefit, but may as well share the wealth.

Despite the new blog format, I have no real intention of making this a personal blog per se, but we shall see….

Posted in glowingminds.co.uk | 1 Comment