corillo181 Posted September 2, 2007 Share Posted September 2, 2007 so i got 2 classes class one{ //do stuff } and i got a second one class two{ //do more stuff } what would i do if i want class one to bne in class 2 class two{ $one = new one(); } ? } Quote Link to comment https://forums.phpfreaks.com/topic/67616-solved-call-class-in-side-of-class/ Share on other sites More sharing options...
trq Posted September 2, 2007 Share Posted September 2, 2007 <?php include 'one.php'; class two { private $one; function __construct() { $this->one = new one(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67616-solved-call-class-in-side-of-class/#findComment-339669 Share on other sites More sharing options...
corillo181 Posted September 2, 2007 Author Share Posted September 2, 2007 so if i have a method i would call on it by $this->one->method(); ? Quote Link to comment https://forums.phpfreaks.com/topic/67616-solved-call-class-in-side-of-class/#findComment-339694 Share on other sites More sharing options...
Ken2k7 Posted September 2, 2007 Share Posted September 2, 2007 That's OOP. And $this refers to the current class to get the variable one and then tell it to create a new one object. Quote Link to comment https://forums.phpfreaks.com/topic/67616-solved-call-class-in-side-of-class/#findComment-339695 Share on other sites More sharing options...
corillo181 Posted September 2, 2007 Author Share Posted September 2, 2007 i made it work it was just the way i posted i just wasn't using the right method name. Quote Link to comment https://forums.phpfreaks.com/topic/67616-solved-call-class-in-side-of-class/#findComment-339699 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.