Since the introduction of PHP 5 in 2004, PHP has had an object model worthy of that description and became a truly modern language for use on the web. Earlier PHP scripts would have been of the kind where, to quote from Alice’s Adventures, you would “Begin at the beginning, and go on till you come to the end: then stop.” Nowadays that very procedural approach is less common in PHP, so this article takes a look at some of the basic object oriented features available in the language and shows some examples of using them with code examples.
Category Archives: php
Confident Coding: San Francisco
Personally I’ll be speaking about git and also about SSH and things that are not FTP, and anything else I get asked about on the day. The variety of skills in the speaker lineup of this event, organised by the lovely @estellevw, is frankly imporessive and I can’t wait to meet all the speakers and attendees! I’m not often in the US at all (I’m a very reluctant traveller and I’m actually there for ZendCon the week after) so this is a rare opportunity for me.
The event is open to everyone, but if you don’t identify as female and you want to attend, please bring with you someone who does – and either way you can make use of my discount code! Simply buy a ticket, entering LORNA20 at the checkout for 20% off the ticket price.
Hope to see you there :)
PHP for Drupalistas
This spring Emma Jane and Lorna Jane were chatting about PHP and Drupal and workshops and came to the conclusion that Drupal developers were not necessarily equipped for Drupal 8. With all of the Drupalisms in the Drupal code, it can sometimes be difficult to implement code that is both a Drupal best practice and a PHP best practice. While there are many workshops on how to teach PHP developers how to Drupal, there were no workshops teaching Drupal developers how to PHP. Until now!
My theory is that most developers working with CMSes like Drupal think they don’t know much PHP … but of course they actually know quite a lot! The newer versions make more use of OOP and new PHP features, but nothing that’s really rocket science (although the symfony components are very nice). This course is a chance for us to give a more solid grounding to those skills that developers just pick up along the way, and give some time to master those skills in a safe environment. Continue reading
Skills Allied to PHP
In October, I’ll be delivering a tutorial at the mighty PHPNW Conference which contains very little PHP. Why? Because I think, as developers, it’s our other professional skills that suffer. As a consultant, I work with lots of different teams, and it is very rare for code to be the problem (and the one time it was, it wasn’t the only problem!).
In web development, our biggest challenges are not writing code, we can do that. But getting the code safely from one place to another, with many people’s work preserved, having our platform(s) correctly configured and understanding how to use them, making use of the tools in the ecosystem which will help us improve the quality of our code; these are the big challenges we face, and that’s why I proposed this workshop and why I think all these topics are important. Continue reading
Validating Email Addresses in PHP
$email1 = "nonsense.something@dottiness"; // not a valid email
$email2 = "[email protected]"; // valid email
$clean_email1 = filter_var($email1, FILTER_VALIDATE_EMAIL); // $clean_email1 = false
$clean_email2 = filter_var($email2, FILTER_VALIDATE_EMAIL); // $clean_email2 = [email protected]
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 frameworks offer equivalents, and I’m sure many of those are wrapping this too.
Installing PEAR Packages Offline
However I’m now in a situation where I might need to install PEAR packages with a connection that may or may not be working, and I’m not sure exactly which packages I might need, so I wanted to know whether I could use PEAR as my packaging tool even when I wasn’t able to reach the usual channels. And guess what? I can! Continue reading
Speaking at CakeFest 2012
PHP 5.4 Benchmarks
PHP’s Magic __invoke() Method and the Callable Typehint
__invoke()
. Continue reading Bit.ly API: Bundles and Short URLs
To get around this, I used their API to make a page which lists my bit.ly bundles, and creates shortlinks for each of them (once you’ve created a shortlink for a given URL once, bit.ly just re-uses the same ones the next time you ask to shorten the same URL, so this is less silly than it sounds).
In case the code is helpful, I thought I’d share. Continue reading