class member's altering problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zawar
Forum Newbie
Posts: 2
Joined: Tue Mar 07, 2006 2:23 am

class member's altering problem

Post 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]
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

What error is displayed?

P.S. Could you please use [ p h p ] tags around your code?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply