PHP Puzzlers #2

Here’s another short post detailing some odd behavior in PHP.

Let’s have a look at the following simple piece of code:

$arr = array(
  1 => 'Hello',
  1.5 =>'World',
  true=>"!"
);
var_dump($arr);

What would the output of this be? Surprisingly this does the following:

array(1) {
  [1]=>
  string(1 ...
more ...

PHP Versions

Common Crawl is a fantastic project which provides search data to people. This provides an opportunity for smaller companies to create a search engine using the results, among other things.

By default PHP adds an “X-Powered-By” header which provides the PHP version. Since the common crawl data also provides header ...

more ...

PHP Puzzlers #1

PHP has some idiosyncrasies that can cause odd or counter intuitive behavior. This will be a series of short posts covering some of these situations.

Let’s have a look at the following simple piece of code:

$arr = array('foo','bar','baz');


foreach($arr as &$item){
   echo "First array: ".$item ...
more ...

Generators In PHP

PHP 5.5 added a really nice feature: Generators.

Generators allow you to create a function that returns an list of items without having to create a (possibly very large) array first.

Here’s a simple “classic” generator example. Suppose you wanted to create a range function (PHP provides this ...

more ...

PHP Syntax Checking

The CLI to php allows checking for syntax errors using php -l I’ve created a very basic script which will recursively check folders for php files with syntax errors. It’s intended to quickly show syntax errors in a large application. It’s available here: https://github.com/JimMackin ...

more ...