Assign variable in class to use several times

Discussion in 'PHP' started by trecords, Feb 6, 2012.

  1. #1
    Hi,

    I want to load one variable in one class in two or more different functions. Please see my example:
    class functions {
    	public $data;
    	
    	function a() {
    		global $data;
    		b();
    	}
    	
    	function b() {
    		global $data;
    	}
    }
    PHP:
    After passing function a data not executes on function b as global variable. I don`t want to rename same $data for second time to use it on send function. So I need proper solution for this, how can I make $data to be executed in function b() also.
     
    trecords, Feb 6, 2012 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    the best approach here is by using abtract class, place the variable in an abstract class then simple extend it to all child classes
     
    bartolay13, Feb 6, 2012 IP