[FEATURE-REQUEST] function_alias

From: Date: Fri, 09 Jun 2000 17:52:38 +0000
Subject: [FEATURE-REQUEST] function_alias
Groups: php.dev 
Request: Send a blank email to php-dev+get-20817@lists.php.net to get a copy of this message
Hi, I know PHP already has alias functions, declared at the implementation level. Can we also have , say boolean function_alias(string $name,string $alias [,int $flag]) ? I was thinking a good API for any classes should use descriptive names, but in actual coding, short names can be handy. Also this would help in `Interface' normalization. e.g. I use in two wrapper classes Http_Request and Http_Response the Servlet API function names (e.g. getParameterNames, getParameter, setCookie, setContentType, etc.) It's clear what getParameter means, but I would like to have instead of: $Request = new Http_Request (); if ($Request->get_Parameter('foo') == 'bar'){} an alias: function_alias("Http_Request::getParameter","p"); $rq = new Http_Request(); if ($rq->p('foo') == 'bar') {/* do action */} Also, in the PHPLIB code there are some similar shorthands in the DB_* classes, iirc. It would be cool to be able to alias PHP functions, given the lack of programatic function naming along the extensions, so we would be able to use something like: $p = DB_PERSISTENT; switch (DB_IFACE) { case 'MySQL': function_alias ("get_Connection","mysql_${p}connect"); break; case 'PgSQL': function_alias ("get_Connection","pgsql_${p}connect"); break; /* ... */: default: function_alias ("get_Connection","error_no_db_iface"); } To avoid overwriting of aliases a third parameter can be use to set this rule (as in `extract' array function). That would help also for another request of `functions sandbox' (a requested functionality) should one be able to say: function disabled () {;} function_alias("system","disabled", ALIAS_REPLACE|ALIAS_FINAL); function_alias("popen","disabled", ALIAS_REPLACE|ALIAS_FINAL); etc. where ALIAS_FINAL would mean no further aliases can de done, and ALIAS_REPLACE to overwrite the original. Currently parts of this can be achived by declaring another function. I don't know what's the overhead of "routing" the call through such a function, and how expensive it is on lots of calls. what do you think? -- teodor

« previous php.dev (#20817) next »