CategoryPHP

PHP related information

Add a Git repository as a package using Composer for PHP

There isn’t much documentation on how to setup PHP libraries using Composer that are not in Packagist; one way to do this is as a package. If you specify the version number of the library (or other code) that you want you can fetch them from zip files, Subversion or Git. This way you don’t need to add any Composer files (such as composer.json) to the library itself, which is handy if...

Install Zend Framework 2 and Doctrine 2 using Composer

Since the installation instructions aren’t overly clear (I don’t find) for how to install more than one package to a project, you need a composer.json that looks akin to the following: { "require": { "doctrine/orm": "*", "zendframework/zendframework": "2.0.*" } } What caught me out is that all the packages you want need to be in the...

Install Composer for PHP with detect_unicode = Off as a php.ini file does not exist

If you are having problems installing Composer, using the method mentioned on their website: curl -s | php You may get an error like the following (which will be because PHP CLI may have a different php.ini or not be present at all) #!/usr/bin/env php Some settings on your machine make Composer unable to work properly. Make sure that you fix the issues listed below and run this script again: The...

Persisting Zend controller variables whilst forwarding actions

Quick tip for when you’re trying to persist variables in a controller using Zend Framework, if you’re using a class property for your action controller then it’s because using the _forward action helper will actually re-instantiate the controller class, so your member variables (properties) will be reset. Thus if you declare them static then they will persist between _forward...

Numeric range queries using Zend_Search_Lucene, working around the bugs

Zend_Search_Lucene is a PHP implementation of the Lucene full-text searching engine. Whilst some of it works well, other bits don’t quite, such as performing range queries. The most common error for range queries is along the lines of an Zend_Search_Lucene_Search_QueryParserException that states Range query boundary terms… This, as may have guessed, is that queries that work fine in...

Use Zend_Log_Writer_Firebug to debug AJAX requests using Firebug

Debugging a page request in PHP, simple right? Either output to the page or command-line using something like var_dump, or use a step-through debugger to go through line-by-line. The advantage of the former is that it’s quick, and although the latter is more thorough it can be quite time-consuming. However when you’re debugging an AJAX request, you can’t simply output as...

Using Zend_Db_Profiler_Firebug to show database queries per page

Although ZFDebug is a great tool, it does require you to show the toolbar when you need to check something. Whilst this is fine for developers or administrators, it’ll probably confuse regular users. Therefore if you’re trying to debug something a regular user is doing, you may need another way to see what database queries are being run. Luckily Zend Framework has both a logger and a...

Checking $mixed parameter type for PHP methods

Something that we came across this morning, and something to be wary of in the future, is how you check the parameter type of a $mixed variable in a method signature. i.e. Is the parameter a string or a number? If you’re not careful you can get unexpected results… As we’ve discovered, using ctype functions can be dangerous as ctype_digit() for example expects a string as a...

“concrete5 cannot parse the PATH_INFO or ORIG_PATH_INFO information provided by your server.”

Thought I’d take a look into concrete5 to see what is was like, and it’s the first open source PHP project installer I’ve come across in ages that complained about anything other than filesystem permissions. PATH_INFO? Most other projects use different mechanisms/variables to do a similar job I assume… Anyways, go to the concrete5 install directory and create a .htaccess...

Using PHP late static binding to define static arrays as subsets for child classes

OK, the title might sound a little confusing, but the concept it relatively simple. Basically it’s using an array in a child class that contains some of the items that appear in the array in the parent class. Which just means you have a list of all of the things in the parent, and a list of some of those things in every child. Like a list of options such as colours, types, etc. Imagine that...