Introduction to PHP OOP

This is the first in a series of articles about using PHP to do objected oriented programming, or OOP. They were originally published elsewhere but are no longer available at that location, so I’m reposting them here.

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.

Continue reading

Confident Coding: San Francisco

While I’m in the US in a week or so, I’ll be joining a stellar lineup at Confident Coding on October 20th in San Francisco. This is a by-women, for-women event to let us get together in a safe space where there are no stupid questions, and try to cover those tricks that it seems like everyone knows, but we all had to learn sometime!

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 :)

PHPNW Tutorial Day

I’ve spent the last few days at PHPNW – it was amazing and inspiring and incredibly sociable from beginning to end but I wanted to share some thoughts about tutorial day in particular. For context, I delivered a full-day tutorial at PHPNW this year, entitled “PHP Tools”, containing the following topics:

  • git
  • apache virtual hosts
  • api documentation
  • static analysis tools
  • profiling with xhprof
  • deployment with phing

Somewhere along the line my attendees were unexpectedly efficient (or I was impatient) and we ended up ahead of my planned schedule, so I asked if anyone had any questions to fill the final hour or so. Continue reading

Git Cheat Sheet

Today I thought I’d share my “cheat sheet” for git – the commands that I use on a day-to-day basis. I’ve used entirely the command line tools, since those are the same on every platform. GUI tools and IDE plugins are available for git so it is worth taking a look at what is available for the development environment you use.

Checkout/Clone

In git, you don’t checkout code, you clone a repository. You end up with a local repository on your filesystem, which behaves as both the repo and as your working copy. In git, you always clone the whole repo, not a subdirectory, and the metadata is all stored at the top level, in a directory called .git.

When you are ready to clone the repo, create the directory to store it in and change into it. Then type:

git clone [url]

Here’s an example, showing a clone of my private joind.in repo on github. Continue reading

Github API Access Tokens via Curl

I’m working on some demos for a tutorial I’m giving next month and since I’d like to show off Github’s API, I needed an access token for it. They have the usual web flow but I’m cutting as many corners as I can to keep the demos nice and quick, so I looked into the support Github has for generating an API key programmatically. Continue reading

API Documentation with IODocs

I write a lot of APIs, and I also preach that your API isn’t finished until it has excellent documentation. Which is great, but that means I therefore have to lead by example and document my APIs :) Enter iodocs from the talented folk at Mashery.

Iodocs is a node.js application (which is fun for a PHP developer. Most developers write a bit of JS, but this one hasn’t). You describe your API and all its methods in JSON, and then iodocs presents an interface for you to enter API keys, add parameters to each request and press the “try it!” button. This makes your API call and shows you the results on screen, which seems like a great way to demonstrate what all the various parameters do!

iodocs screenshot
Continue reading

Do Open Source with Git and Github

This article originally appeared in the May 2012 php|architect magazine.

Often I find absolutely competent programmers, who aren’t involved in open source, either because they don’t know how to approach a project, or because they just aren’t sure how the process even works. In this article we’ll look at one example, the conference feedback site joind.in, and how you can use GitHub to start contributing code to this project. Since so many projects are hosted on github, this will help you get started with other projects, too.

The tl;dr Version for the Impatient

  1. Fork the main repo so you have your own github repo for the project
  2. Clone your repo onto your development machine
  3. Create a branch
  4. Make changes, commit them
  5. Push your new branch to your github repository
  6. Open a pull request

This article goes through this process in more detail, so you will be able to work with git and github projects as you please.
Continue reading

PHP for Drupalistas

There’s an exciting new venture coming up soon – something I’ve been working on with Emma Jane for a while (yes, Lorna Jane and Emma Jane, we know) – it’s called phpfordevelopers.com. From the site:

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

Posting Raw Data with Curl

This week I’ve been working on a feature which handles an incoming API call from an external source (actually Paypal’s IPN service). Making external calls into my development platform isn’t how I usually work, so instead I captured the body of the request that was being sent, and replayed it against my local script using curl.

I put the data into a separate file, data.txt and then used curl to direct that data at my local URL:

curl -X POST http://localhost/app/test.php --data @data.txt

I find this approach useful for testing, but since I had to look up how to do it, I thought I’d put it here for reference!

The Quest for a Payment Gateway

Although I’ve been “making websites” for a lot of years, I’ve mostly avoided the kind where people actually pay for anything. The result of this is that I built Bitestats (elevator pitch: sign up and get a printable summary report of your web stats every month by email) but then got busy and never built the bit where people can actually pay to use it.

I recently carved out some time to correct this situation, and fell into an absolute pit of confusion when I tried to figure out what my options even were. My requirements are that my customers are global, I am UK-based, people will set up a regular subscription, and I don’t have (and I think I don’t want) a merchant account at this point. I’m not PCI compliant and have no intention ever to attempt that. This post is an attempt to round up some things I found out along the way. Continue reading