Page 1 of 1

class member's altering problem

Posted: Fri Mar 17, 2006 4:13 am
by zawar
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi Experts ,
                   I have a problem .below is code.......

Code: Select all

class A{
	var $defined="This is defined";
	var $undefined="This is undefine";
	function foo(){
		if(isset($this)){
			print $this->defined;
		}
		else print $this->undefined;
	}
}
class B extends A{
	function bar(){
		A::foo();
		$this->defined.="From Class B";
		$this->undefined.="From Class B";
		
		
	}
}
$a=new A();
$a->foo();
A::foo();
$b=new B();
$b->bar();
B::bar();
?>
so in class B i want to concat the string "From Class B" in the variables $defined ,and $undefined ,but giving errors.
please solve it or Suggest a solution to alter the variables....


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Mar 17, 2006 7:10 am
by mickd
What error is displayed?

P.S. Could you please use [ p h p ] tags around your code?

Posted: Fri Mar 17, 2006 8:05 am
by jmut
This is defined
Notice: Undefined variable: this in C:\Program Files\Apache Group\Apache2\htdocs\testclasses.php on line 10
This is defined
Notice: Undefined variable: this in C:\Program Files\Apache Group\Apache2\htdocs\testclasses.php on line 10

Notice: Undefined variable: this in C:\Program Files\Apache Group\Apache2\htdocs\testclasses.php on line 16

Notice: Undefined property: defined in C:\Program Files\Apache Group\Apache2\htdocs\testclasses.php on line 16

Notice: Undefined property: undefined in C:\Program Files\Apache Group\Apache2\htdocs\testclasses.php on line 17
This is what this code returns with error_reporting(E_ALL) on php 4.4.1

I don't see any errors...but trully I don't like this notices

Posted: Fri Mar 17, 2006 8:19 am
by feyd
when calling a class staticly, you cannot reference it with $this, as it won't exist. self::$varName is to be used instead.