Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3368 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3363 invoked from network); 11 Jul 2003 21:39:07 -0000 Received: from unknown (HELO herald.cc.purdue.edu) (128.210.11.29) by pb1.pair.com with SMTP; 11 Jul 2003 21:39:07 -0000 Received: from localhost (wm-cpu1.itcs.purdue.edu [128.210.11.233]) by herald.cc.purdue.edu (8.12.9/8.12.9/herald) with ESMTP id h6BLd7YO005230 for ; Fri, 11 Jul 2003 16:39:07 -0500 (EST) Received: from cspan-157.c-spanarchives.org (cspan-157.c-spanarchives.org [208.13.57.157]) by webmail.purdue.edu (IMP) with HTTP for ; Fri, 11 Jul 2003 16:38:32 -0500 Message-ID: <1057959512.3f0f2e5829ec6@webmail.purdue.edu> Date: Fri, 11 Jul 2003 16:38:32 -0500 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2-cvs Subject: Weird behavior for $this variable in PHP4 From: fuhs@purdue.edu (Josh Fuhs) Hello, I'm getting a problem with $this being defined where it shouldn't be. The code that I'm writing is a little weird in order to compensate for the lack of some OO features in PHP4. The PHP script at the bottom should give the behavior I'm referring to. Is PHP5 in a more-or-less stable state? Are PHP4 extensions completely compatible with PHP5? Josh var1=0; } function init(){ global $static_class1; $static_class1 = new Class1(); } function getVar(){ /* Check for $this. This is a way of making a static method and a regular method with the same name. */ /* $this is defined here directly after called from the Class2 constructor. */ if(isset($this)){ return $this->var1; } else { global $static_class1; $static_class1->getVar(); } } } class Class2{ function Class2(){ $a=Class1::getVar(); } } Class1::init(); $a=new Class2(); ?>