NYCPHP Meetup

NYPHP.org

[nycphp-talk] Handling empty values in hashes

paul at devonianfarm.com paul at devonianfarm.com
Thu Jul 17 15:08:04 EDT 2008


> Of course it is possible to create a class with this behavior using
> SPL, but that doesn't take care of the superglobals and there might be
> performance problems.
>
> -John Campbell

Well,  I've got a 'framework' that I use for my own projects that I call "PHP on Nails".  It has several levels,  and "level 0" is the most mature.  It's mostly about configuration management,  tightening error handling and reducing with variations between environments.

It introduces a few single-letter functions,  such as

Q($string):  almost the same as echo(htmlspecialchars($string)) except it maps the empty string to     Your designer and junior programmers ~might~ actually use it in a template.  I'm thinking about expanding UTF-8 unicode characters to numeric form here too.

G($key) and P($key):  which replace $_GET and  $_POST while doing a few kinds of filtering.  If the key is undefined,  it returns the empty string.  Whitespace gets trimmed from the beginning and end of the strings.  magic_quotes_gpc is undone if set.

Perhaps it's a bit crazy to use single character function names,  but my take is that these function greatly improve the security and reliability of PHP applications IF people actually use them.  If the names were like

get_and_filter_post_variable

they wouldn't get used.  Someday I'll release the level 0 library and blog about it.
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080717/76d7121c/attachment.html>


More information about the talk mailing list