Prefix function name problem
| From: | Guillaume Lecanu | Date: | Mon, 29 Mar 2004 17:03:04 +0000 |
| Subject: | Prefix function name problem | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-26856@lists.php.net to get a copy of this message | ||
Hi,
I have make a PHP lib to create functions equivalent of HTML tags for
make "valid" page.
This is the equivalent of mod_cgi in perl.
An example :
table(array (style => 'mytable', width => '80%').
tr(
td(array (width=>'50%'), "Hello").
td(array (width=>'50%'), "World")
)
)
This coding style is very usefull, but i can't propose this lib to PEAR
because all functions must be prefixed by the name of the package.
1st Solution - Make an object :
$x = new HTML_Tags()
$x->table(array (style => 'mytable', width => '80%').
$x->tr(
$x->td(array (width=>'50%'), "Hello").
$x->td(array (width=>'50%'), "World")
)
)
It's a little more complex and for each function called, the $x instance
must be add in "global" declaration.
2nd Solution : Prefix function name
By default, all functions are dynamicaly create, so i can prefix them by
the name of the package (for the PEAR standard) and let the developper
decide to the prefix string ('', 'html' or by default the name of the
package).
What do you think about theses solutions please ?
PS: I have heard the PHP 5 would be add the "[]" alias of the array
instruction : [1,2,3] equivalent to array(1,2,3)
But i have test the PHP 5 and this doesn't works..
Anybody have informations about this ?
Thanks