The Zend Certification Exam is a step in the right direction for PHP developers looking to enhance their resume and prove their skills. It is becoming accepted by recruiters worldwide and in some cases, demanded by corporations seeking employees. Achieving this certification is no easy task, though. It requires working experience with PHP, as well as the technologies associated with it.
The test consists of 70 questions and you have 90 minutes to complete them. You may skip between questions and revisit those that you skipped. You will likely finish the examination in 30 to 45 minutes (purely personal experience), so take the other half and check your answers.
PHP 5.3 introduces a much requested feature for object-oriented programmers: namespaces. At the time of this writing, version 5.3 of PHP was in development, but is planned on being released in the near future.
One of the purposes object-oriented programming is to remove ambiguous development and data access items. This basically means identifying common functionality and creating the most reusable framework possible, typically in the form of classes. When creating this functionality, you will begin to have issues with naming conventions and narrowing down functionality even further. To resolve this scoping issue, namespaces allow you to contain those bits of code even more.
With the increasing use of web services and communications via HTTP, XML has become an industry standard for sending and receiving data among systems. Every language seems to have multiple ways to parse XML, each more complicated than the other. This presents a problem for developers.
The majority of the time, developers need to read/write XML files without complex features such as advanced namespacing and XSD validation. It seems that opening an XML file, reading and using the content takes forever as you constantly need to reference hundreds of pages of documentation, Google examples of each method or function in the documentation; it never ends.
Since the release of PHP5, SimpleXML has been available for creating and editing XML files or strings. Don’t let the name fool you, it doesn’t represent the simplicity of its capabilities. It does, however, mean the implementation of this extension is simple! PHP has other XML capabilities such as DOM, XMLWriter and XMLReader in the event you need those advanced features not offered by the native SimpleXML extension.
I have completed the major functionality to the SOAP integration of the zip code services. The following methods can be used to get the data you need:
getDistanceByZip - Get the distance from one zip code to another
getZipsByRadius - Get GPS information within (X) miles of a zip code
getLocalTime - Get the local time for a zip code
I am going to describe each function in depth, and give examples of each in a few languages. If you have suggestions to this service, feel free to contact me using the contact form.
About the Service
This web service is provided absolutely free. Please don’t abuse this. If requests start getting out of hand and bringing my server to its knees, I will start limiting the number of queries per user per day. I don’t want to do this, but I do like my server actually serving :).
It is an RPC style web service, as it really isn’t complicated and is limited to a very specific audience. It’s also easier for developers to use and understand in comparison to document-literal.
Update! Due to the demand for an easier interface, I have developed a SOAP service offering more functionality and requires less coding on your end. You may see the overview here: http://www.phpfever.com/soap-zip-code-web-service.html.
Ok….
So I’ve created this script based off of the GPS info. It allows you to specify a zip code and radius (in mileage), and it will return the following values in XML:
Moving from a procedural system to object-oriented can be a daunting task. One feature to assist you is the MySQLi class, which allows for an object-oriented approach to database manipulation. This tutorial gives insight into the structure and basic usage of the MySQLi class. If PDO isn’t an option for you, then try MySQLi!
SQL injection is increasingly becoming a problem for developers, especially PHP. This tutorial will give some insight into what SQL injection is, and how simple it is to protect your code from it.
PHP5 has introduced many new features for object-oriented programming. One of those misunderstood, useful keywords is the ?final? keyword.
The final keyword allows us to do three things:
It prevents child classes from overriding a method
It prevents a class from being extended if the class is marked “final”
Serves as a reminder to future developers of your code that the class has a purpose, and should not be messed with further
Don’t get me wrong, this keyword can be abused as with all other aspects of code. Just becuase you have finished writing a class, it doesn’t mean that you should mark it as final.
The true purpose of the “final” keyword is to simply protect methods or classes that are not meant to be modified or extended. For instance, you have a method that has 3 parameters. This method is used heavily throughout your application, and in the instance that it breaks, your application is rendered virtually useless. What could cause this type of situation?
This method creates an HTML select menu and allows for a default value. However, John want’s extend the class, and add a paramter between $select_name and $arr_values that allows for an onchange. Even with a default value this will cause issues with the previous usage of this method. To protect it, simply put the “final” keyword before the access control keyword:
This is an extremely simple tutorial on making a script that counts the lines of code in an application you have built.
First off, let’s get some things out of the way. I will be introducing a function called glob(). Here is the syntax for it:
array glob ( string pattern [, int flags] )
Here is the definition taken from php.net:
The glob() function searches for all the pathnames matching pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells. No tilde expansion or parameter substitution is done.
Returns an array containing the matched files/directories or FALSE on error.
Here are the flags that can be used:
GLOB_MARK - Adds a slash to each item returned
GLOB_NOSORT - Return files as they appear in the directory (no sorting)
GLOB_NOCHECK - Return the search pattern if no files matching it were found
GLOB_NOESCAPE - Backslashes do not quote metacharacters
GLOB_BRACE - Expands {a,b,c} to match ‘a’, ‘b’, or ‘c’
GLOB_ONLYDIR - Return only directory entries which match the pattern
Note: Before PHP 4.3.3 GLOB_ONLYDIR was not available on Windows and other systems not using the GNU C library.
GLOB_ERR - Stop on read errors (like unreadable directories), by default errors are ignored
Note: GLOB_ERR was added in PHP 5.1
In this tutorial, we won’t need any flags, but they are there for the taking.
First off, let’s view the code needed to get the files in a single directory:
Line one simple grabs an array of all files with an extension of “php” as $file_name and then starts the loop through each file. The second line explodes each line of code for each file into an array variable called $file_array. Line three loops through each line of code, checks to see if the line is a comment or an empty line, and then counts it if it isn’t. After all is said and done, the variable $lines will contain the total number of lines of every PHP file in my current directory that is not a comment of empty line! Pretty sweet, huh?
This will come in handy for those of you who are statistic freaks or work in a corporate environment.