ryanc1256 ryanc1256 - 1 year ago 111
PHP Question

how to check if a constant exists in php

So im using a php framework called fuelphp, and I have this page that is a html file so i can't use php in it, and I have another file that has a top bar in it, which my html file will call though ajax. And I was just asking, how do we check if a constant exists in php? aka (the fuelphp framework file locations)

so these are constants I need to check (well I only have to check one of them)

define('APPPATH', realpath(__DIR__.'/fuel/app/').DIRECTORY_SEPARATOR);
define('PKGPATH', realpath(__DIR__.'/fuel/packages/').DIRECTORY_SEPARATOR);
define('COREPATH', realpath(__DIR__.'/fuel/core/').DIRECTORY_SEPARATOR);
require APPPATH.'bootstrap.php';


I realised that these aren't variables they are constants...

Answer Source

First, these are not variables, but constants.

And you can check their existence by using the defined() function :

bool defined ( string $name )

Checks whether the given constant exists and is defined.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download