Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Testing if class is defined returns a notice

Im trying to check if a class is defined, and if it isnt then define it, so I used:-
if (!class_exists(DB)) {
     echo "Class doesnt exist";
}

Open in new window


However when I run it, I get the echo statment, but along with:-
Notice: Use of undefined constant DB - assumed 'DB' in /var/www/vhosts/htdocs/dbConf.php on line 15

I know I can swtich warnings and notices off, but during development I prefer to keep them switched on.

Ive also tried using:-
if (!defined(DB)) {
     echo "Class doesnt exist";
}

Open in new window


But get the same results :-S

Any advice???
0
tonelm54
Asked:
tonelm54
  • 2
1 Solution
 
Marco GasiFreelancerCommented:
You have to use quotes:

if (!class_exists('DB')) {
     echo "Class doesnt exist";
}

Open in new window

0
 
Marco GasiFreelancerCommented:
Function class_exists89 requires the first parameter is a string, taht is the class name, not the class itself: http://php.net/manual/en/function.class-exists.php

Cheers
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now