Demonic Posted August 1, 2007 Share Posted August 1, 2007 I don't know what its called but the Objects look like so: $var->var->var(); How does that work? Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/ Share on other sites More sharing options...
teng84 Posted August 1, 2007 Share Posted August 1, 2007 actually its a class thin when you say $db->connect(); it means that the class db is calling the function connect in the class Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312452 Share on other sites More sharing options...
Demonic Posted August 1, 2007 Author Share Posted August 1, 2007 Naw not like that. $var->var->var(); I seen some IPB source and it does some stuff like that. Not $var->var(); I already know how classes work I want to know how the above object works though. Its unique more advanced. Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312454 Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 It's calling the function "var()" inside of the object "var" which was created inside of the object "var" Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312457 Share on other sites More sharing options...
Demonic Posted August 1, 2007 Author Share Posted August 1, 2007 Can you show me an example of how I would do that? Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312461 Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 <?php class foo { public var $bar; protected function __construct () { $this->bar = new bar(); } } class bar { public function foo_bar() { return "FUBAR (F'd Up Beyond All Repair)"; } } $blah = new $foo; echo $blah->bar->foo_bar(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312472 Share on other sites More sharing options...
teng84 Posted August 1, 2007 Share Posted August 1, 2007 hitman I always wonder why you guys use public in the class isnt class is made to act as public???? then y??? Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312475 Share on other sites More sharing options...
Demonic Posted August 1, 2007 Author Share Posted August 1, 2007 PHP 5 stuff, it wont work correctly with PHP 4. How would I do this just using PHP 4? I got an error with your example: Parse error: syntax error, unexpected T_VAR, expecting T_VARIABLE in C:\SERVER\www\foobar.php on line 4 I'm using WAMP 5 PHP 5.2.3 Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312481 Share on other sites More sharing options...
hitman6003 Posted August 1, 2007 Share Posted August 1, 2007 I suppose that it isn't necessary to declare a function public, since according to the manual a method without a declaration is automatically public (http://us2.php.net/manual/en/language.oop5.visibility.php#language.oop5.visiblity-methods). I do it mostly for consistency, and also because I suppose that I'm slightly OCD. Remove the public / protected from the vars and methods, and change the function named "__construnct" to the name "foo". Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312483 Share on other sites More sharing options...
teng84 Posted August 1, 2007 Share Posted August 1, 2007 although we both know that its not necessary its being stated by PHP.net so i guess ill go with you even if it doesnt make any difference Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312486 Share on other sites More sharing options...
Demonic Posted August 1, 2007 Author Share Posted August 1, 2007 I suppose that it isn't necessary to declare a function public, since according to the manual a method without a declaration is automatically public (http://us2.php.net/manual/en/language.oop5.visibility.php#language.oop5.visiblity-methods). I do it mostly for consistency, and also because I suppose that I'm slightly OCD. Remove the public / protected from the vars and methods, and change the function named "__construnct" to the name "foo". Ok cool it worked perfectly: <?php class foo { var $bar; function foo () { $this->bar = new bar(); } } class bar { function foo_bar() { return "FUBAR (F'd Up Beyond All Repair)"; } } $blah = new foo; echo $blah->bar->foo_bar(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312487 Share on other sites More sharing options...
btherl Posted August 1, 2007 Share Posted August 1, 2007 IMHO, specifying things which are the default anyway (such as public) is good practice. It adds to the documentation, and ensures your code will run correctly even if the defaults change. It also helps catch bugs, as you may not always be correct in what you assume the default to be. Quote Link to comment https://forums.phpfreaks.com/topic/62765-solved-how-do-some-programmers-do-this/#findComment-312489 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.