Naming php function and php class based on your variable name
I have php class and php function that are used together , since im making few of the edits to same files on and off 开发者_JS百科I have to rename my class and function based on the file I am working on so , the code is like this
class myclassName{
function myfunctionName{
}
}
and later used as
$myvariable = myclassName::myfunctionname($getwhatineed);
so I would like to do this
$default_cf_name ="DesiredName";
class prefix_$default_cf_name{
function prefix_$default_cf_name{
}
}
You may want to read up on Object-Oriented PHP for Beginners.
For what it's worth, that looks like a pretty horrible thing to do. You can achieve that at least by writing the class creation code into a string and passing it through eval()
but you may make a lot of your fellow coders angry with that.
To understand better why I asked , I am reusing same class and same functions over and over again and get name clashing , to avoid it I was thinking of the var naming the functions/classes but this saved me lot of time
http://www.digimantra.com/technology/php/avoid-fatal-error-redeclare-function-php/#comment-258354
a simple
if(!function_exists('myfunc')){
}
check fixes the issue , same thing with
if(!class_exists('myclass')){
}
精彩评论