|
|||||||||||||||||||||||
Aktuell Texte Der Comic Impressum Kalender Suche PHP-Klassen Container-Wizard main.s21 |
|||||||||||||||||||||||
Kategorien
{{login}}
|
paran: Basic
paran is not going to work without Basic. Basic is simple, small and absolutely central. When I started to work for another company, which had their library in place already, I made it a condition that I might at least use some components of Basic lest to loose the last vestiges of my sanity. Basic is just a collection of static methods which I turned into a class because I did not want to have a single include("functions.php") around. The central method is Basic::xmltag(), which you can search within the library and will find a lot. It will turn a string (tag name) and an array (attributes) into an XML opening tag:
<?php
This definitely beats the usual mess of slashes and strings when people concatenate XML-Tags by hand is certainly more elegant when having conditions:
<?php
The latter is horrid, not to mention that it calls for a security issue if $name is not properly sanitized using htmlentities(). xmltag will properly mask all values. Along that line come two handy relatives, Basic::xmltagEnclose and Basic::xmltagUnsafeEnclose:
<?php
I have been criticized for using such a simple concept as opposed to DOM or similar, more object oriented mechanisms. Well, first of all, I know how to handle DOM. However, it should be clear that a method which keeps a representation of the entire DOM tree in memory and where every element is an object is a little bit more complex and has more overhead. xmltag served me very well so far. dump and var_dumpTake me as a fan of "echo debugging". Some people scoff at this, but I'll usually get a bug faster with a few echoes than firing up all this debugging stuff which is not very trivial when you want to debug on a remote server and so on. Basic::dump and Basic::var_dump just add <pre></pre> around calls of print_r and var_dump - wonder why the PHP guys didn't put that as an option. constructI never liked the way of dynamically constructing objects with new $object(), as it looked as primitive as $function(), which I had long before replaced by call_user_func_array, first alone and then within paran: Callback. construct builds objects, internally using Reflection.
<?php
The latter does not just feel "nicer", it also looks nicer, allows for dynamic parameters and is easier to identify (globally search for Basic::construct and you get all runtime instantiations in your project). Dieser Text ist Teil der Serie Paran in Action paran: Autoloader KommentierenBitte beachten: Kommentare sind nicht sofort sichtbar, sondern werden erst nach einer kurzen Prüfung freigegeben, sofern keine rechtliche Beanstandung vorliegt. |