0

I have php class and php function that are used together , since im making few of the edits to same files on and off 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{
       }
  }
1
  • As a general rule, if you make a change, and then have to apply the same change in multiple files, you're doing something wrong. Commented Oct 10, 2011 at 18:27

3 Answers 3

3

You may want to read up on Object-Oriented PHP for Beginners.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

sorry but using eval() is not an option , the code must be safe and I cannot guarantee since there are more than 5 devs working on the project, but like I advised above simple check helps allot.
0

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')){
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.