seventheyejosh Posted September 13, 2009 Share Posted September 13, 2009 Hello all! A few more questions. If my index.php is as follows (all this is theoretical, and not syntax checked): session_start(); require_once "classes/class_a.php"; require_once "classes/class_b.php"; and they were as follows a: class a{ protected $user='Josh'; protected function something(){ } } and b was class b extends class a{ public function another(){ echo $this->user; something(); } } would that work? or would I have to do: require_once "class_a.php"; require_once "class_b.php"; $a=new a(); $b=new b(); in my index.php? or would any of this work if the classes arent in the same file? also, is it a faux pas to use DEFINE in OOP? and I'm almost sure it is, but global is frowned on as well right? Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/174088-oop-oop-define/ Share on other sites More sharing options...
corbin Posted September 13, 2009 Share Posted September 13, 2009 The first way would work, but you would have to do $this->something() instead of just something(). Some languages figure out method scope on their own (like Java for example), but in PHP you have to put the $this. Also, if you need to define something, you could always use a class constant. class SomeClass { public const SomeConst = 5; } echo SomeClass::SomeConst; //Outputs 5 Quote Link to comment https://forums.phpfreaks.com/topic/174088-oop-oop-define/#findComment-917750 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.