Gomesh Posted December 14, 2009 Share Posted December 14, 2009 Hi friends, Pls solve my query . what is the exact use of Scope Resolution Operator( in classes.. Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/ Share on other sites More sharing options...
mrMarcus Posted December 14, 2009 Share Posted December 14, 2009 well Mr. "Expert Developer", here's the manual: Scope Resolution Operator Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-977240 Share on other sites More sharing options...
mikesta707 Posted December 14, 2009 Share Posted December 14, 2009 It resolves scope =P Yeah the double colon ( operator is used when you want to access static properties, constants, and overridden methods http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php check out the manual A quick example. Say we had a class, foo, and a class footoo that is derived from foo. If foo has a method, bar(), footoo can access that method, even if it overrode it, using the scope resolution operator class foo { function bar() { "I am Foo"; } }//end class class footoo extends foo { function bar() { parent::foo();//note the use of :: echo "And I am footoo"; } } There is more too it though, so check out the manual for the other uses, and examples Edit; Marcus beat me, but i feel this is worth posting Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-977241 Share on other sites More sharing options...
Gomesh Posted December 14, 2009 Author Share Posted December 14, 2009 thanks Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-977268 Share on other sites More sharing options...
ignace Posted December 14, 2009 Share Posted December 14, 2009 class foo { function bar() { "I am Foo"; } }//end class class footoo extends foo { function bar() { parent::foo();//note the use of :: echo "And I am footoo"; } } Forgot something? Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-977281 Share on other sites More sharing options...
mikesta707 Posted December 14, 2009 Share Posted December 14, 2009 ahh yes it should be class foo { function bar() { "I am Foo"; } }//end class class footoo extends foo { function bar() { parent::bar();//note the use of :: echo "And I am footoo"; } } Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-977282 Share on other sites More sharing options...
ignace Posted December 15, 2009 Share Posted December 15, 2009 class foo { function bar() { echo "I am Foo"; } }//end class class footoo extends foo { function bar() { parent::foo();//note the use of :: echo "And I am footoo"; } } Nevermind you were missing an echo statement Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-977937 Share on other sites More sharing options...
Gomesh Posted December 17, 2009 Author Share Posted December 17, 2009 why we use global in any function for example:- function get_director() { global $movie_director; global $director; $query_d = "SELECT people_fullname " . "FROM people " . "WHERE people_id='$movie_director'"; $results_d = mysql_query($query_d) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-979103 Share on other sites More sharing options...
ignace Posted December 17, 2009 Share Posted December 17, 2009 @Gomesh usage of global variables is wrong much like the function die() they are considered to be bad practice. Quote Link to comment https://forums.phpfreaks.com/topic/185129-pls-clear-my-confusion/#findComment-979112 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.