[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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