rem Posted November 10, 2006 Share Posted November 10, 2006 Hello,Could you please point me towards the right path here?I have a PHP5 class with multiple functions. Somehow, within those functions, there is a pattern which is repeated across the code. I thought, why not do a function to take care of the pattern and call it within the other functions whenever is needed ?ex: [code]<?phpClass Example { public $value; public function my_pattern() { //do something with $this->value; } public function some_other_function() { $test = new Example; //do something with $test->my_pattern(); }}?>[/code]I don't know what am I doing wrong but $this->value is not assigned within my_pattern() function ... My head hurts bad ... Please help ??? :'(...Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/ Share on other sites More sharing options...
JasonLewis Posted November 10, 2006 Share Posted November 10, 2006 whats with the public stuff. just do var $value; and remove the public from the start of the function. it probably wont effect anything but i find that code annoying for some reason..now...Instead of calling it by $test->my_pattern() from inside the function call it like $this->my_pattern()if thats what your wanting to no. Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/#findComment-122606 Share on other sites More sharing options...
rem Posted November 10, 2006 Author Share Posted November 10, 2006 [quote author=ProjectFear link=topic=114514.msg465938#msg465938 date=1163156538]whats with the public stuff. just do var $value; and remove the public from the start of the function. it probably wont effect anything but i find that code annoying for some reason..now...Instead of calling it by $test->my_pattern() from inside the function call it like $this->my_pattern()if thats what your wanting to no.[/quote]Thanks a lot, I'll give that a try ... but that "public stuff" isn't how PHP5 handles it now? Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/#findComment-122610 Share on other sites More sharing options...
rem Posted November 10, 2006 Author Share Posted November 10, 2006 Yeap, it worked! Thanks a lot ProjectFear. I could swear I tried that myself and it didn't then... Anyway, I'm sure must been screw things up somehow. Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/#findComment-122614 Share on other sites More sharing options...
redbullmarky Posted November 10, 2006 Share Posted November 10, 2006 ProjectFeat - var $value will work on both PHP4 and 5, but strictly, the correct way is to declare a var/function within a class is either public/private/protected which is the way PHP5 utilises. someone correct me if i'm wrong, but i'm pretty sure using 'var' in PHP5 throws a notice as deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/#findComment-122626 Share on other sites More sharing options...
JasonLewis Posted November 11, 2006 Share Posted November 11, 2006 i am using PHP5 and i am user var with no troubles at all.... Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/#findComment-122936 Share on other sites More sharing options...
roopurt18 Posted November 11, 2006 Share Posted November 11, 2006 Using var with PHP5 will cause a warning if you have your error reporting set correctly. Quote Link to comment https://forums.phpfreaks.com/topic/26811-function-within-function/#findComment-122951 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.