Jump to content

Recommended Posts

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]<?php

Class 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!

Link to comment
https://forums.phpfreaks.com/topic/26811-function-within-function/
Share on other sites

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 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?
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.