Before using PHP, Perl was my language of choice for web applications, so I am not short of experience in the language.
The common denominator between PHP and Perl is that they both have roughly the same roots: they are both Unix-like languages, loosely based on C. As such, one of the biggest advantages and the biggest disadvantages in having already learnt Perl is look-alikes. That is, functions or constants that look almost the same, but are different. Or, worse yet, functions that are called the same name but function differently.
For example, the PHP function substr() looks just like the Perl functions substr(). Happily enough, it works in precisely the same manner in both languages. On the other hand, a function like rtrim() looks to many like the Perl function chomp() because it trims whitespace from the right-hand side of a string. However, it's actually quite different in that the Perl version only trims new-line characters and returns the number of characters that have been trimmed, whereas the PHP version trims all whitespace by default, and returns the trimmed string.
I strongly recommend that you consult a reference (either this book or the PHP manual at http://www.php.net/manual) if you ever have any doubts as to how a function works. Don't just assume that because a function has the same name that it works in the same way!
Want to learn PHP 7?
Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: A note for programmers coming from C, C++, or Java >>
Previous chapter: How to use this book
Jump to:
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.