Renlok Posted April 12, 2009 Share Posted April 12, 2009 Is it possible to define some thing outside of a class and read it inside the class i have something like define('THIS', 1); class that { function that() { echo (!defined('THIS')) ? '' : ''; } } and it cant see the definition how can i use it like a global variable Link to comment https://forums.phpfreaks.com/topic/153749-use-of-define-and-classes/ Share on other sites More sharing options...
premiso Posted April 12, 2009 Share Posted April 12, 2009 Yes it is. define('THIS', 1); class that { function that() { echo "THIS was : " . THIS; } } $that = new that(); Should echo out THIS was 1 once the class is instantiated. If THIS is not defined it would echo out THIS with a notice of an undefined constant. That is the point of a constant, it can be used anywhere within a script as long as it is defined before you try to use it. Link to comment https://forums.phpfreaks.com/topic/153749-use-of-define-and-classes/#findComment-808006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.