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 Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.