Narendra Dhami

My Site

Archive for the ‘PHP’ Category

Setting up continuous integration for PHP using Hudson and Phing

Posted by Narendra Dhami on October 13, 2010


he difficulty with Unit Testing is keeping it up. It is very easy to slip into poor habits and before you know it there’s a huge chunk of code with no tests. Possibly a huge, badly designed chunk of code, that didn’t benefit from having tests written before it was coded. Before you know what’s going on, you end up with a project that you really can’t write tests for, because retrofitting the tests is near impossible.

For me, there are two critical reasons for Unit Testing:

  • Enforcing good design
  • To be able to write tests, you need to be able to zero in on a “unit” of code, isolating it from all the rest of your 1,000,000 lines of web application. Writing Unit Tests forces you to design systems that have loose coupling because otherwise it is impossible to test.

  • Allowing changes to be made in confidence
  • Without Unit Tests, you get to the point where no one really wants to make any changes to the code. This is especially true in a commercial environment, where many people have worked on the code, including some key team member who has since left. Unit Tests allow you to make changes to one part of the code and be pretty convinced you haven’t messed up something else.

    More …

    Advertisements

    Posted in PHP | 1 Comment »

    25 Excellent PHP Tools That Enhance The Way You Develop

    Posted by Narendra Dhami on February 10, 2010


    PHP has grown to become one of the most wide-spread server-side scripting language that’s used on a daily basis in a variety of ways. For the most part, almost every developer that’s introduced to this programming language uses it and becomes fond of it at some point. With the support of a very large community, this incredibly fast technology is taking over other server-side scripting languages. If you conduct a quick search on the subject you’ll find countless ready-to-use scripts and a fist-full of quality frameworks.

    Here you can see we’ve complied 25 Excellent PHP Tools That Will Enhance The Way You Develop in detail. Take a look at a few of these tools, assess which ones address your needs, and take advantage of them. After all, they’re there for us to use.

    PHP_Debug

    PHP_Debug is very useful open-source tool that allows you to output processing times of your PHP and SQL, check the performance of specific code blocks and get variable dumps in graphical form.

    PHPUnit

    PHPUnit is a great testing framework that belongs to the xUnit family of testing frameworks. It’s perfect for writing and running automated tests on your PHP code.

    phpDocumentor

    phpDocumentor, (phpdoc or phpdocu) is an auto-documentation tool for the php language. Similar to Javadoc, and written in php, phpDocumentor can be used from the command line or a web interface to create professional documentation from php source code.

    Scavenger

    Scavenger is an open source real-time vulnerability management tool. It helps system administrators respond to vulnerability findings, track vulnerability findings, review accepted or false-positive answered vulnerabilities, and not ‘nag’ system administrators with old vulnerabilities.

    Xdebug

    Xdebug is a PHP extension that helps you debug your scripts by providing a lot of valuable debug information. If a script fails to execute properly, Xdebug will print a full stack trace in the error message, along with function names, parameter values, source files, and line numbers.

    MODx

    MODx helps you take control of your web content. It’s a fast and reliable Open Source PHP application framework, it frees you to build sites exactly how you want and make them 100% yours.

    PHP Object Generator

    PHP Object Generator, (POG) is an open sourcePHP code generator which automatically generates clean & tested Object Oriented code for your PHP4/PHP5 application.

    CakePHP

    CakePHP is one of the most widely used rapid development framework for PHP. It provides an extensible architecture for developing, maintaining, and deploying applications.

    PHP/SWF Charts

    PHP/SWF Charts is a simple and powerful PHP tool that lets you create attractive web charts and graphs from dynamic data. Use PHP scripts to generate or gather the data from databases, then pass it to this tool to generate Flash (swf) charts and graphs. This tool allows the integration of PHP scripts, and Flash provides the best graphic quality.

    BlueShoes

    BlueShoes is a comprehensive application framework and content management system. It is written in the widely used web-scripting language PHP. BlueShoes offers excellent support for the popular MySQL database as well as support for Oracle and MSSQL.

    Propel

    Propel is an open-source Object-Relational Mapping (ORM) library written in PHP5, written on top of PDO. It allows you to access your database using a set of objects, providing a simple API for storing and retrieving data. Propel allows web application developers to work with databases in the same way they work with other classes and objects in PHP.

    PHP_Beautifier

    PEAR is a framework and distribution system for reusable PHP components. You will be able to automatically format and clean-up your PHP4 and PHP5 source code.

    Phing

    Phing is a PHP project build system or build tool based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP “task” classes make it an easy-to-use and highly flexible build framework.

    CodeIgniter

    CodeIgniter is very a powerful PHP framework with a small footprint. It was built for PHP coders who need a simple and elegant toolkit to create full-featured web applications.

    Securimage

    Securimage is an open-source free PHP CAPTCHA script for generating complex images and CAPTCHA codes to protect forms from spam and abuse. It can be easily added into existing forms on your website to provide protection from spam bots.

    SimplePie

    SimplePie is a clear-cut PHP class that can help you work with any RSS feed. It was written in PHP and is Flexible, this way beginners or advanced users can benefit from it alike.

    Pixy

    Pixy is a Java program that performs automatic scans of PHP 4 source code, aimed at the detection of XSS and SQL injection vulnerabilities. Pixy takes a PHP program as input, and creates a report that lists possible vulnerable points in the program, together with additional information for understanding the vulnerability.

    Phormer

    Phormer is a PHP-Based PhotoGallery Manager application, that helps you to store, categorize and trim your photos on the web with various helpful features.

    xajax PHP Class Library

    xajax is pretty much a PHP class for simplifying your workflow when working with PHP AJAX applications. It gives you an easy-to-use API for quickly managing AJAX-related tasks.

    PHP-GTK

    PHP-GTK is an extension for the PHP programming language that implements language bindings for GTK+. It provides an object-oriented interface to GTK+ classes and functions and greatly simplifies writing client-side cross-platform GUI applications.

    Minify!

    Minify is PHP 5 app that helps you combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers.

    gotAPI/PHP

    gotAPI is a useful online tool for quickly looking up PHP functions and classes.

    PECL

    PECL is a very useful directory of all known PHP extensions and a hosting facility for downloading and developing PHP extensions.

    Koders

    Koders is the leading search engine for open source and other downloadable code now contains over 2 billion lines of code within its repository. This is very useful when you’re searching for various PHP source codes that you may need to replace or enhance, or when you’re not exactly sure of which codes to use, you can search, test, and compare.

    Few More

  • Valgrind
  • YSlow
  • Page Speed
  • Original From : http://www.reencoded.com/2010/02/06/25-excellent-php-tools-that-enhance-the-way-you-develop/

    Posted in PHP | Leave a Comment »

    PHP Frameworks

    Posted by Narendra Dhami on February 10, 2010


    Here are the list of some popular PHP Frameworks:

    Posted in PHP | Leave a Comment »

    PHP Patterns

    Posted by Narendra Dhami on January 18, 2010


    Below is the better explanation of possible design patterns which can be implemented in PHP:
    http://giorgiosironi.blogspot.com/search/label/practical%20php%20patterns

    Posted in PHP | Leave a Comment »

    PHP Charset FAQ

    Posted by Narendra Dhami on December 16, 2009


    http://kore-nordmann.de/blog/php_charset_encoding_FAQ.html, A very good FAQ about charset.

    Posted in PHP | Leave a Comment »

    Adapting The Joel Test To Web Development

    Posted by Narendra Dhami on November 11, 2009


    Nearly a decade ago, Joel Spolsky came up with a method by which to evaluate software development shops that has come to be known as the Joel Test. This crucial test evaluates a software development company on the basis of twelve criteria points; Spoksly said that “a score of 12 is perfect, 11 is tolerable, but 10 or lower and you’ve got serious problems. The truth is that most software organizations are running with a score of 2 or 3, and they need serious help, because companies like Microsoft run at 12 full-time.”

    When Joel wrote the test, there wasn’t much development for the web; the little that was being done wasn’t being done in any of the modern languages that we write in today. In fact, Facebook, Myspace, Twitter, Gmail, and LinkedIn hadn’t even been invented yet.

    Today’s world makes heavy use of web-based software (the term “software as as a service” keeps floating around). And so, it is necessary to update Joel’s test in order to properly apply it to web development. This has been done by some folks, but I will do it again, mostly because I disagree with them. More…

    Posted in PHP | Leave a Comment »

    Setting up continuous integration for PHP using Hudson and Phing

    Posted by Narendra Dhami on November 11, 2009


    he difficulty with Unit Testing is keeping it up. It is very easy to slip into poor habits and before you know it there’s a huge chunk of code with no tests. Possibly a huge, badly designed chunk of code, that didn’t benefit from having tests written before it was coded. Before you know what’s going on, you end up with a project that you really can’t write tests for, because retrofitting the tests is near impossible.

    For me, there are two critical reasons for Unit Testing:

  • Enforcing good design
  • To be able to write tests, you need to be able to zero in on a “unit” of code, isolating it from all the rest of your 1,000,000 lines of web application. Writing Unit Tests forces you to design systems that have loose coupling because otherwise it is impossible to test.

  • Allowing changes to be made in confidence
  • Without Unit Tests, you get to the point where no one really wants to make any changes to the code. This is especially true in a commercial environment, where many people have worked on the code, including some key team member who has since left. Unit Tests allow you to make changes to one part of the code and be pretty convinced you haven’t messed up something else.

    More …

    Posted in PHP | Leave a Comment »

    PHP Certifications. Where, Why And, How To Get Them

    Posted by Narendra Dhami on October 21, 2009


    Becoming a certified PHP developer, does not mean that you become a better developer but, it can surely give you some more chances to get the job. We tried to do a little research about PHP certifications, where to get one, what it takes to get one and why you need it. We also tried to find some online tests for you in order to prepare yourself before you actually go for it.

    Where?

    Zend

    zendlogoThe industry’s standard can not be anything else than Zend’s Certification. Zend has been running the PHP certification program for more than 4 years and has certified nearly 5000 PHP developers. Actually, there is a contest running at the Zend site that will reward the 5000th certified developer with $5000. This is what they say:

    We are rapidly approaching the 5000 PHP Zend Certified Engineer and we would like to give the 5000th person to achieve this prestigious accomplishment a special gift of $5000 in Zend Training Units and if we reach this milestone before ZendCon09 – a free entry pass to the conference!

    There are guides and online exams that can help you prepare yourself to get the certification but you have to pay some money to get to them except the Zend Framework Certification study guide that comes free of charge.

    There are 2 ways to get the certificate. The first one is by purchasing the examination from the Zend online store and the second one is by scheduling an exam with Pearson Vue, the company with which Zend certifications are executed.

    Upon certification, you are listed to the Zend Yellow Pages, where a lot of employers look into for PHP developers and you get special discounts on Zend PHP conferences worldwide.

    W3Schools

    w3certW3Schools has been a web development resource heaven for many years now. It is not luck that it is the first site to visit for most of people who want to learn web technologies and development. Recently, w3schools has been rolling out a PHP certification program. You can take the exam online and you should be supervised by a person that you select so, you have to choose a supervisor wisely in order to add credibility to your certificate. This does not add value to the certification though IMHO.

    The examination consists of 70 multiple choice or true/false questions about PHP (it requires fundamental knowledge of SQL too) and you have 70′ (minutes) to complete the test. To become certified, you have to have 75% of the questions answered correct and, if you get more than 95% you get an excellency degree. The service will inform you about your pass/fail status immediately after the end of the examination and if you have passed the exam, you will be sent a PHP developer certificate. Your supervisor should sign the certification which, you can use to prove your PHP knowledge. You can verify your certification online at a unique URL that the certificate points to.

    The w3schools certification costs $75 and you can pay by Paypal or credit card.

    Brainbench

    bbBrainbench is dedicated to helping organizations use assessment science to predict employee success. Using the Brainbench assessment platform, companies improve hiring and retention, boost training success, enhance customer satisfaction, and increase profitability. One of the ways to do this, is by certifying several aspects of job criteria. Brainbench has tests for you to certify your knowledge for nearly anything from aerospace to programming and of course, for PHP.

    You can take the examination online for $49.95 .

    ExpertRating

    hd03ExpertRating is an ISO 9001:2000 company that offers hundreds of popular certifications and tests which are suitable for students, professionals, job seekers and companies.

    ExpertRating tests consist of timed, multiple choice questions with one or more correct answer/s to each question. Each test covers basic to advanced questions on each topic. The test taker should keep in mind that the knowledge of applied skills gained through real work experience is emphasized rather than theoretical knowledge. For achieving certification the test taker must score at least 50% marks. Clearing the test with a score of 80% or more will be credited as a distinction and mentioned on the certificate of accomplishment.

    To get PHP certified with ExpertRating, you have to pass a 40 multiple choice questions test. You have 45 minutes to answer all questions. The certificate costs $9.95

    OST

    OST_LogoIn OST’s unique online Learning Sandbox®, students have access to their own web programming and Unix shell-based database environments where they will apply new skills as they are presented by completing real-world projects.

    Completion of the 4-course series earns students a Certificate of Professional Development from the University of Illinois Office of Continuing Education. All courses are certified by the University of Illinois Department of Computer Science, and students receive Continuing Education Credits upon completion of each course in the series.

    The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux MySQL platform.

    The certificate costs $398

    What does it take?

    To become a certified PHP developer, besides PHP knowledge, you might need to be aware of :

    • HTML
    • SQL (MySQL most commonly)
    • Web administration
    • XML

    Why?

    Because as stated on the top of this post, being a great PHP developer sometimes might not be enough. Sometimes, you have to prove your knowledge to an employer to get the job and, being a PHP certified developer is one great way. Employers from around the world can find you easier since, most of the times, your name will be listed as a PHP developer on pages associated with employers.

    OK I like it. Where do i start?

    Here is a good list of tests and quizzes to help you get accustomed with most of the exams above:

    Orginal From

    Posted in PHP | 1 Comment »

    25 New & Useful PHP Techniques & Tutorials

    Posted by Narendra Dhami on October 14, 2009


    PHP is the most popular and widely accepted server side scripting language among developers due to its easy to learn nature, free of cost and its large ever increasing helpful community. Here are 25 useful PHP techniques and tutorials, most of which have been published only in this year. More …

    Posted in PHP | Leave a Comment »

    PHP Quizes

    Posted by Narendra Dhami on September 25, 2009


    PHP Quiz part 1

    Simple things of PHP can be just as fun as the advanced things in
    PHP!
    To prove that I wanted to make a small quiz, and here it is.

    Below you’ll see 10 pieces of PHP5 code, the goal is to figure
    out the code and know the output before you actually run it.
    Have fun!

    Comment and closing tag

    <?php //
    Without cheating.. What will you see when you run this single line of
    ?\?> php code

    Echo print and get what

    <?php
      // What do you expect from this ?
      echo print( 1 ); ?>

    What wil eval to true

     <?php
      // How many times will we get ‘true’ ?

      $boolean  = false;
      echo ($boolean) ? ‘true’ : ‘false’;

      $boolean  = ‘0’;
      echo ($boolean) ? ‘true’ : ‘false’;

      $boolean  = ’00’;
      echo ($boolean) ? ‘true’ : ‘false’;

    First a cast, then an increment, but what is shown?

    <?php
      // What number will you get to see?
      $integer = (int) ‘PHP’;
      echo ++$integer;

    Float boat

     <?php
            // What number will be
    output?
            $a = 0.1 + 0.7;
            echo (int) ($a*10) + 1 ;

    Array key fun

     <?php

            $a[ 1 ] = “The one”;
            $a[“a”] = “The second”;
            $a[“1”] = “The who?”;
            $a[“A”] = “CaSe FuN”;
            $a[“01”]= “The last”;

            echo count($a); // How many
    do you expect?

    Array count

     <?php

            $one    =
    range(1, 3);
            $two    = 7;
            echo count($one) +
    count($two); // How much will the be?

    Array key existence

     <?php

            // Will it be isset?

           
    $a             
    = range(10,20);
           
    $a[11]          = “The one
    and only”;
           
    $a[’11’]        = null;

            unset($a[1]);
            if (isset($a[11])) {
                   
    echo “Yes, it’s isset!”;
            } else {
                   
    echo “No, it’s not isset.”;
            }

    Array evil sort

     <?php

           
    $a      = array(0, 1, 0.1=>’a’,
    1.1=>’A’);
            sort($a);

            echo count($a); // Is it what
    you expected?

    Array reference voodoo

    <?php

            $a =
    array(‘i’,’b’,’b’,’q’,’b’,’!’);
            foreach($a as
    &$value)  {}
            foreach($a as
    $value)   {}

            echo   
    str_rot13( implode(”, $a) ); // how many letters
    ?

    PHP Quiz part 2

    A short quiz this time, but that doesn’t make it less fun. Do you
    know the answer to all of them? Get a cup of coffee and kill 10 minutes
    with round two…

    As always, think of the answer before you execute the code or
    look it up. You can find round one here.

    Array pointer

    What will the output be ?
    $array = range(0,5);
    next($array);
    foreach($array
    as $v) {
      echo $v;
    }
     

    ArrayAccess and isset fun

    isset or not isset, thats the question.
    $a          = new ArrayObject;
    $a[‘fubar’]
    = NULL;
    $null       = NULL;

    if (isset($null))
    {
            echo 1;
    } else {
            echo 2;
    }

    if (isset($a[‘fubar’])) {
            echo 1;
    } else {
            echo 2;
    }

    if (array_key_exists(‘fubar’,
    $a)) {
            echo 1;
    } else {
            echo 2;
    }

    Typo?

    The output might be confusing..
    array(4>‘a’)

    References

    How many notices will be thrown?
    error_reporting(E_ALL);
    function a( & $array) {}
    function b($array) {}
    a($array);
    b($array)

    OR or || – operator precedence

    What will the output be?
    echo
    ( 1
    ? 0 : 1
    or 1 ),
    ( 1
    ? 0 : 1
    || 1 );
     

    Nesting structures

    Will this error, or not?
    if (1):
        echo ‘one’;
        if(2) {
            echo ‘two’;
        }
    else:
        echo ‘not
    one’
    ;
    endif;

    PHP Quiz part 3

    Welcome to another part of the PHP Quiz series, again some
    interesting questions to crack your brain about. If you have some nice
    additions or questions, be sure to leave a comment. Enjoy part three!

    As always, think of the answer before you execute the code or
    look it up. You can find round two here.

    Unset cast

    What is the type of $a and what is the type of $b
    $a = “A”;
    $b = (unset) $a;
    var_dump($a,
    $b);
     

    Form fun

    What will the output be?
    <form method=“post” action=“” enctype=“text/plain”>
        <input name=“search”
    type=“text”>
        <input type=“submit”>
    </form>
    <?php
            error_reporting( E_ALL );
            echo (string) filter_input(INPUT_POST, ‘search’);
    ?>
     

    Fun with strings

    Strings in PHP are versatile, but how versatile are they… What
    will the output be?$juggling = “Itffkhmf”;

    $rox = “Spy”;

    $b = $c
    = “”;
    for ($i=0;
    $i<strlen($juggling); $i++) {

        $b .= $juggling[
    $i ];

        $b++;
    }
    for ($i=0;
    $i<strlen($rox); $i++) {

        $c .= $rox[
    $i ];

        $c–;
    }

    var_dump( $b,
    $c );

    Referenced returning

    Do you know the referencing details? What will the output be?class RR {
      public $varA = “z”,
             $varB
    = “z”,
             $varC
    = “z”;

      function
    & getA() {
        return $this->varA;
      }

      function
    & getB() {
        return $this->varB;
      }

      function
    getC() {
        return $this->varC;
      }
    }

    $rr = new RR;

    // Option A,
    method only

    $a = $rr->getA();

    $rr->varA = “a”;

    // Option B,
    both method and assign

    $b = & $rr->getB();
    $rr->varB = “b”;

    // Option C,
    assign only

    $c = & $rr->getC();
    $rr->varC = “c”;

    var_dump($a,
    $b, $c);

    For what it’s worth

    $obj    = new stdClass;
    $int    = 1;
    $string = “a”;

    echo
    ($obj
    * 2),
    ($int
    * 3),
    ($string
    * 4);

    Global precedence

    function multiply($b) {

        $a = 100;
        global $a;

        return $a * $b;
    }

    echo
    multiply(100);
     

    Making the (seemingly) impossible, possible

    Don’t use codepad to figure out whats happening, since that gives
    a big hint right away. Try it on the CLI and think about what is
    happening first.class A {
      private $A;
    }

    class B extends A {
      public $AA;
    }

    // How many
    keys, and what are the keys?

    var_dump( (array) new B()
    );
     

    Posted in PHP | Leave a Comment »