Posts

Showing posts from August, 2012

Treb - A simple framework for PHP

Introducing: Treb – A simple framework for PHP http://eliw.wordpress.com/2012/08/31/introducing-treb-a-simple-framework-for-php/

Object Scoping

http://blog.ircmaxell.com/2012/08/object-scoping-triste-against-service.html

Validating Emails in PHP

A very quick snippet today because I've told two people to use this approach in the last few days and both of them told me they didn't know about it. How to check if an email address is valid in PHP: use one of the  Filter functions , like this:   $email1 = "nonsense.something@dottiness" ; // not a valid email $email2 = "dotty@something.whatever" ; // valid email   $clean_email1 = filter_var ( $email1 , FILTER_VALIDATE_EMAIL ) ; // $clean_email1 = false $clean_email2 = filter_var ( $email2 , FILTER_VALIDATE_EMAIL ) ; // $clean_email2 = dotty@something.whatever The Filter extension was new in PHP 5.2, but is one of the unsung heroes of the language. It's rare for me to ever describe one approach as the "right" way to do something - but for validating data, Filter really is excellent, offering both validating and sanitising filters and generally making it super-easy to clean up incoming variables. Many of the framework

Are PHP Developers functophobic?

I do feel this is the way things are going, although it seems they may already be this way!.. http://nikic.github.com/2012/08/10/Are-PHP-developers-functophobic.html

Coding Standards

I've recently come across http://pear.php.net/manual/en/standards.php , which got a few ideas jumping about my head, and reminded me of a tool I use from time to time for curiosity purposes more than anything - phpcs or PHP CodeSniffer ( http://pear.php.net/package/PHP_CodeSniffer/ ). I occasionally run phpcs against some of the codebases I work on, just to see if there seems to be any structure or standard being followed throughout the system. The results are usually verbose and stressful to even begin trying to fix, and sometimes wonder if coding standards are used effectively anywhere. With the many techniques and ways of completing a task in PHP and with PHP developers becoming more and more OOP oriented, developers are beginning to play around with inheritance and abstraction, namespaces and interfaces, getters and setters - All the buzzwords and terms which lead to more and more overly complex code for no reason other than - "we used all of the above", and as a resu

include, require, include_once or require_once

Well the question Today is which is the best or correct one to use? There are a few reasons to choose between include and require I suppose, based on the importance of the file you are 'including'.  If I was including a config or settings files with critical information in it, or a bootstrap loader file which all my files need, I'd be inclined to use require over include - as the file is Required, and not an optional file that the site can load without.  Take on the other hand if I was pulling in a file with some adverts on it, or a banner on the site from another template file, I'd be more inclined to use include, as this isn't mission critical to the site loading - Ok I'd really like it there, but if there is an issue for whatever reason, I still want the rest of the page to continue loading. Next comes the question of include/require vs include_once/require_once . I guess the age old discussion of performance comes to mind, if I know for a fact (and I s

Portable PHPUnit

So looking into PHPUnit again this morning, and would be great to have a "portable" set up.  The usual way to set up PHPUnit is to install the PEAR package.  However it turns out it is possible to have a more portable set up which can be moved between my XAMPP usb pen, WAMP laptop setup and LAMP stack at work, without all needing to have PHPUnit installed under all the separate hosting accounts. Found this post the other day:  http://stackoverflow.com/questions/4801183/php-is-there-a-portable-version-of-phpunit .  Well in actual fact I found the process on another site, but that one sums it up pretty well I think.  And I don't think you'd need to use the git clone's either, you could I suppose download the source from github in an archive and extract it. The main thing to remember is to update your include_path() to include all the paths to the modules you've downloaded though. I will have to have a play around with this, as I have PHPUnit PEAR package

Me and TDD

OK, so I'm looking into Test Driven Development (TDD). Now, I've looked into working with it before within the PHP environment I use daily, but sometimes feel a bit overwhelmed by it all. Every time I read up about it, I always get a different slant on things, and always learn something different or new from the time before, and feel I am getting to grips with the basic principles now. The big question is whether to start from scratch or attempt to write tests for the existing codebases I have. I have a personal codebase, albeit pretty dated, and then there are the (many) styles and codebases used at work for me to choose from.  Part of the dilema is if I use any work code, I can't post it online or use it in my own work, although, to be honest, when work finishes, usually the last thing I want to do is come home and be glued to the laptop writing code.  So that explains why I haven't made much progress over the past 3 years, and from time to time dip into blog a