📖 Posts | 📎 Development | 🔖 PHP

Defaulting optional parameters

If you have a function that takes an optional parameter – e.g. function blah($xx,$yy='Default',$zz){ …. You can use the function and ensure that the optional parm always takes the correct default (even if the definition changes) by passing a NULL to it. e.g. … $mydate=blah($something,NULL,$more); …

📖 Posts | 📎 Development | 🔖 PHP

Handle web parameters gracefully in PHP

Handle web parms (Call as: myParms('report');) # Ensures that the given parm is always set function myParms($var) { global $$var; if(isset($_REQUEST[$var])){ $$var=$_REQUEST[$var]; } else { $$var=''; } }