Jump to content

Undefined Constant


The Little Guy

Recommended Posts

I have a class, and some of the methods take parameters like this: EXTRACT_SYMBOL, EXTRACT_NUMBER, etc. when I run this, I get the following:

Notice: Use of undefined constant EXTRACT_SYMBOL - assumed 'EXTRACT_SYMBOL' in C:\wamp\www\phpLive\index.php on line 11

 

What should I do, not to turn the errors off, but to make the code valid? What ever I need to do, I want to do within the class/method, and not outside it if possible.

 

public class myClass{
    public function myFunction($value, $action){
        switch($action){
             case EXTRACT_SYMBOL:
                 // Do some stuff
                 break;
             case EXTRACT_NUMBER:
                 // Do some stuff
                 break;
        }
    }
}

$cls = new myClass();
$cls->myFunction('Some string', EXTRACT_NUMBER);

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/241693-undefined-constant/
Share on other sites

looks like I want this

define('EXTRACT_SYMBOL',1); // a constant

 

Do I put that above my class?

 

Like this:

define('EXTRACT_SYMBOL',1);
public class myClass{
    public function myFunction($value, $action){
        switch($action){
             case EXTRACT_SYMBOL:
                 // Do some stuff
                 break;
             case EXTRACT_NUMBER:
                 // Do some stuff
                 break;
        }
    }
}

$cls = new myClass();
$cls->myFunction('Some string', EXTRACT_NUMBER);

 

or inside the constructor?

Link to comment
https://forums.phpfreaks.com/topic/241693-undefined-constant/#findComment-1241321
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.