Using PHP the JavaScript Way


In JavaScript, passing lambda functions (callbacks) as parameters for later execution is a very common use case. That approach is very popular due to its simplicity, scopes encapsulations and native support of asynchronous programming. Unlike JavaScript, PHP is not (natively) asynchronous language, however despite that, it recently got a great support for lambda functions as well. Next, are several use cases where it may be useful.








Read More

PHP scripts tester

One of the things that I’m working on, requires creating and executing a lot of small PHP scripts. Sometimes it’s about code snippets, sometimes it’s a bunch of functions and methods that have to be tested. Of course the best way to work on your code is within your preferred IDE (I’m using CodeLite), but when we speak about bunch of small scripts, you cannot even call it a project. Since most of the work that we, web developers, is done on the browser, then why should we leave it to write code anyway? Hmm.. especially if it’s about small scripts.



PHP Scripts Tester Screenshot
PHP Scripts Tester Screenshot

Read More

Back to vanilla JS – no more jQuery

Although jQuery is very popular and super convenient framework, in many cases we use it for DOM selectors, AJAX calls, event binding and maybe few more basic operations. Those use cases have become very simple in native JavaScript also. Loading the whole framework or creating pretty big jQuery objects became unnecessary. One of the major problems that jQuery solved for us, was the browsers inconsistency. Nowadays,  The modern browsers including latest versions of IE, have great support of HTML5 and web standards, so the inconsistency problem almost disappeared from our life. In this post I’m going to demonstrate how simple it is to implement the listed above use cases.


Read More

Zend’s Z-Ray

I know that most of the PHP community and open source generally does not like commercial products, however, Zend’s Z-Ray will simplify the debugging and the profiling processes, and that’s what really important. And (!), it’s for free for open source projects. The preview alpha version is also for free.

Well, what is Z-Ray?

Z-Ray is a PHP extension that, for every request to the server, captures the database queries that were executed during the request, all the invoked functions, all the errors and exceptions with their backtrace, resources usage statistics, and more. The captured data is displayed either within an injected toolbar at the bottom of the page, or in “Z-Ray Live”, which displays data about all the incoming requests to the server, on a separate web page. The injected toolbar version of it looks like this:

Zend's Z-Ray on a demo wordpress page
Zend’s Z-Ray on a demo wordpress page

Read More

PHP closures


For those of you who work with JavaScript, the term “closure” isn’t new. However, PHP has a little different interface and implementation for closures.

Well, what is a closure? Closure is an anonymous function, aka lambda function, a function without a name within its scope. What it means? – Usually it’s used to pass a function as a callback argument to another function which expects to receive parameter from type “callable”.

php closures illustration
php closures illustration

Simple example

Here’s an example of a lambda function that is passed to array_filter function

Operator “Use”

So far, so good – until now everything looks fine. However, the real power of PHP closures is in using scope variables – local variables that were defined outside of the lambda function.

Read More

PHP traits


PHP is an OOP language, however, unlike C++, PHP classes cannot inherit from more than one base class. A class might implement several interfaces to cover some specific use cases, but this is absolutely another story. PHP introduced the traits in version 5.4.0. Still, this is not a native multiple inheritance, but it’s a nice feature that might fit many cases in which multiple inheritance is needed.


A trait is not a regular (or an abstract) class that you might want to extend, its definition and syntax are slightly different. The “base class” is defined as a trait from the very beginning, and the syntax is almost the same as for a class. It can be treated as, kind of, extensions for classes.

Let’s start with a simple trait example for error handling. The syntax and the definition of a trait is done in the next way

Read More

Using MongoDB from PHP


NoSql is becoming the new database standard. The top advantages of non-relational databases is the flexibility and the scalability, what makes it very useful for “big-data” services. One of the leading NoSql databases is MongoDB which is maintained  by “10gen” (They provide courses, tutorials and certifications). This post is going to talk about the integration of PHP and MongoDB.

First, the terminology differs a little from RDBMS (relational databases). Tables become Collections because they don’t have a static structure, so calling them tables would be wrong. Rows become documents, because every document is a JSON object and might have different structure from one document to another.



Working with MongoDb from PHP requires installing MongoDb extension. The process is not more complicated than installing any other extension. Just follow the instructions here:


Let’s start with creating a connection, choosing the database and the collection to work with.

Read More

Unit testing and RESTful services

Unit testing is very important, we all know that, and I assume that most of us are familiar with the popular PHP unit testing framework – PHPUnit. As any other framework it has its advantages and disadvantages, but what I didn’t like in it, is the installation process.. Definitely, the installation can be done manually, but I was looking for some simple and light testing framework for my application.


After a brief search on GitHub, I landed on a framework called Testify, which is very light, and provides good functionality. However…

Read More