0

I've built a class file which has a function inside containing various errors. I want to move that function to a config.php file.

How do I carry on using that function now it's inside config.php?

The function:

private function error($errnum=1000) {
    $data = array(
        '1000' => 'Required parameter is missing',
        '1100' => 'Parameter not recognized',
        '2000' => 'Currency type not recognized',
        '2100' => 'Currency amount must be to 2 decimal places',
        '2200' => 'Currencies cannot be the same',      
        '3000' => 'Service currently unavailable',
        '3100' => 'Error in service'
    );  
    $this->result($data[$errnum], $errnum);
} 

I tried using:

require_once("config/config.php");

in the class file but it still shows an error

Parse error: syntax error, unexpected T_PRIVATE

1
  • I'd also like to point out, that error is a slightly too generic/ ambiguous name, for a function anyway. Commented Jan 9, 2012 at 13:38

2 Answers 2

2

If you using it in the Config.php file you must remove the private part.

Then you must include the class instance you use for showing the result. Or you have to replace the $this->result($data[$errnum], $errnum); for something that is not in a class.

So for example something like this :

function error($errnum=1000) {
    $data = array(
        '1000' => 'Required parameter is missing',
        '1100' => 'Parameter not recognized',
        '2000' => 'Currency type not recognized',
        '2100' => 'Currency amount must be to 2 decimal places',
        '2200' => 'Currencies cannot be the same',      
        '3000' => 'Service currently unavailable',
        '3100' => 'Error in service'
    );  
    echo "Error: ".$data[$errnum]."(".$errnum.")";
}

error(2000);

Hope it helps.

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

Comments

1

public, protected and private are only needed inside classes. Your function is not a method, but a standalone function, therefor the private is invalid there. Either move it into a class or remove the keyword.

2 Comments

Thanks. I removed the private. I'm still getting an error though when trying to access that function. return $this->error(1000); is what I'm using. What's wrong with that?
$this also only has meaning within a class.

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.