Method memory handling from an instanced object
| From: | Dan Hardiker | Date: | Tue, 13 Aug 2002 09:57:41 +0000 |
| Subject: | Method memory handling from an instanced object | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-86759@lists.php.net to get a copy of this message | ||
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?
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).
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?
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?
If anyone can let me know how this conceptually works, and (if possible) why.
Thanks,
--
Dan Hardiker [dhardiker@staff.firstcreative.net]
ADAM Software & Systems Engineer
First Creative Ltd