Solved

Testing if class is defined returns a notice

Posted on 2013-11-09
2
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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