Coding Practice

    Date: 05/04/07 (PHP Community)    Keywords: php

    Let's say I want to see if $_REQUEST['id'] is set give variable '$a' that value, and if not give it a default value. The way I would write it is this:

    if (isset($_REQUEST['id'])) {
    $a = $_REQUEST['id'];
    } else {
    $a = "default value";
    }

    My friend would write it like this:

    $a = !empty($_REQUEST['a']) ? $_REQUEST['a'] : 'default value';

    ... his way seems pretty well, better. The variable "$a" is already there, and the conditions for what value to use are being set inside it (as I read it) rather than my way, which checks to see if this other variable exists first; and then sets $a appropriately.

    My question is where can I read up on this practice of writing PHP rather than what I now consider my old, clunky style.

    Source: http://community.livejournal.com/php/563673.html

« Temp Passwords || Security Tips »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home