Re: PHP 4.0 Bug #9005: Static classes sometimes have a $this pointer

From: Date: Wed, 31 Jan 2001 01:54:44 +0000
Subject: Re: PHP 4.0 Bug #9005: Static classes sometimes have a $this pointer
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-45411@lists.php.net to get a copy of this message
chuck@horde.org wrote: i dissagree $this in a static object should point to the default declared object, and if that is unacceptable because u want the the default data to be read only, then it should be allowed for methods at least. example class lubas class { var $tbl = ""; var $fmt = 1; function datfmt($d,$fmt) { return(""); } function lufmt($db,$id,$fmt) { $db->query("select * from " . $this->tbl . " where id=$id"); $db->next_record(); $this->datfmt($db->Record,$fmt); } } // class class lunam extends lubas { var tbl = "names"; var $fmt = 1; function datfmt($arr,$fmt) { return($arr["lname"] . "," . $arr["fname"]); } } right now the only way this class arrangments works is if the top class gets allocated but i belive that lunam::lufmt($db,1,1); should work every thing is static if class::data is not avalible and just class::method in static class then the static data could be written as a constant function class lubas class { function tbl() { return(""); } function datfmt($d,$fmt) { return(""); } function lufmt($db,$id,$fmt) { $db->query("select * from " . $this->tbl() . " where id=$id"); $db->next_record(); $this->datfmt($db->Record,$fmt); } } // class class lunam extends lubas { function tbl() { return("names"); } function datfmt($arr,$fmt) { return($arr["lname"] . "," . $arr["fname"]); } } but either way $this needs to be accessable in static functions or there not wothless but not worth as much as they could and should be right now i use this style of classes and dont like haveing to define a global var, and declare it global evry where it gets used, when it is a static class in evry sence of the word just my 2 cents > > From: chuck@horde.org > Operating system: Linux 2.2 > PHP version: 4.0.4pl1 > PHP Bug Type: Scripting Engine problem > Bug description: Static classes sometimes have a $this pointer > > If you call a static method from within an object, the static method will inherit the $this > pointer of the calling object. This script demonstrates the problem: > > <?php > > error_reporting(E_ALL); > > class StaticClass { > function doSomething() { > echo $this->data; > } > } > > class Instantiated { > var $data; > > function Instantiated($data) { > $this->data = $data; > StaticClass::doSomething(); > } > } > > $ob = new Instantiated('foo'); > > ?> > > This is rather confusing behavior - $this should be out of scope inside static methods no > matter what. > > -- > Edit Bug report at: http://bugs.php.net/?id=9005&edit=1 > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- My opinions are my own and not that of my employer even if I am self employed Tech Net, Inc. --FREE THE MACHINES-- 651.224.2223 627 Palace Ave. #2 karner@tnss.com karner@tnss.mn.org St. Paul, MN 55102-3517 www.tnss.com wanted : adsl/cable modem with static ip at reasonable price accept-txt: us-ascii,html,pdf accept-dat: ascii-delimited,sql insert statments

« previous php.dev (#45411) next »