Re: Method memory handling from an instanced object

From: Date: Tue, 13 Aug 2002 17:53:01 +0000
Subject: Re: Method memory handling from an instanced object
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-86776@lists.php.net to get a copy of this message
--- Dan Hardiker <dhardiker@staff.firstcreative.net> wrote: > Hi All, > > If I was to code something like: > > <?php > > class Example { > var $abc = false; > function Demo($param) { > // etc // > return $param; > } > } > > $ex1 = new Example; > $ex2 = new Example; > > ?> > > There are now 2 variables, both with a copy of the object Example in them. > Now, I would expect the variables in the objects to be duplicated (eg: the > memory space for $ex1->abc to be separate from $ex2->abc). However, is the > method definition the same? Yes the method is only compiled once. Altho when you extend an object the opcodes will get copied. (opcodes being compiled php code) > Is the method definition and contents duplicated each instancing? (eg: if > I have 100,000 instances of an object with a "print()" method - would that > method be copied to each object - or would the reference the same memory > space). Again only compiled once. > If the method is shared, then would a static variable in a method be > shared across the entire class - or would it still reference to that > object instance's variable memory space? Static varibles by definition (in all languages) are across all instances of an object. > If the method is not shared, could this cause an issue with a class that > has a lot of methods being instanced lots of time and taking up lots of > memory? Not an issue. -brad __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com

« previous php.dev (#86776) next »