Solved

Testing if class is defined returns a notice

Posted on 2013-11-09
2
177 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculate values in an array 18 32
Apache/PHP: Cannot make phpinfo() and phpmyadmin work 4 33
php email 2 26
Make custom query_posts look show the excerpt only 9 22
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now