PHP

  • Debug PHP like Pro: Intellij Idea + VirtualBox + XDebug

    VirtualBox + XDebug overview

    For a long time I used to use built-in PHP debugging function like var_dump, debug_backtrace, spl_object_hash etc. That tools are very useful but there is one tool combining all of them. I’m talking about XDebug PHP module. With XDebug you can stop code execution in any place you need and get all information about objects, variables and call stack in one window.

    breakpoint overview

    (more…)

  • Power of Composer packages

    About Composer Packages

    Composer packages makes maintaining your code easier. For example, you have a small library which is used in a few projects at the same time. You want to add a new feature or fix a bug.

    You can go through all projects which are using the library and update them. But what if new update needs to add new dependencies? You should add them manually too. It will take too much time and chance to break something is very high.

    Another way is to package the library in a Composer package and make it accessible somewhere across the Internet (you actually don’t need make it public). In this case you update the code, add required dependencies in config and release a new version. After that, you just go through projects and run a single command in their root directory:

    composer update

    This is much easier than the previous scenario.

    (more…)

  • Composer Basics

    About Composer

    Composer is a tool to manage dependencies in your project. With it you can search, install and remove external packages in your code just in few commands. It tracks information about updates and dependencies using centralized repositories (the largest is packagist.org).

    (more…)

  • PHP closures

    About PHP closures

    Generally PHP closures are constructions of an anonymous function (a function without a name) stored in variable. For example:

    $records=someFunctionToGetAllRecords();
    
    $getRecord = function($recNum)use($records){
        return $records[$recNum];
    }
    
    var_dump($getRecord(10))
    //Will return a specified record from records array
    (more…)