Solved

Testing if class is defined returns a notice

Posted on 2013-11-09
2
181 Views
Last Modified: 2013-11-09
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
Comment
Question by:tonelm54
  • 2
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 39635570
You have to use quotes:

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

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39635571
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question