超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<DatabasesError Reporting>
Last updated: Fri, 22 Jun 2007

New Object Model

In PHP 5 there is a new Object Model. PHP's handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or pass as a parameter to a method. In the new approach, objects are referenced by handle, and not by value (one can think of a handle as an object's identifier).

Many PHP programmers aren't even aware of the copying quirks of the old object model and, therefore, the majority of PHP applications will work out of the box, or with very few modifications.

The new Object Model is documented at the Language Reference.

See also the zend.ze1_compatibility_mode directive for compatability with PHP 4.




add a note add a note User Contributed Notes
New Object Model
rbates at delete_this_part dot artbeats dot com
11-Aug-2004 10:26
The __get() function will not be called recersively. In other words, __get() will not be used if you attempt to retrieve an undefined property from $this while currently in __get(). Here is an example:

<?php

class Greater
{
function __get($name)
{
if ($name == "hi") {
return $this->hello;
} else if ($name == "hello") {
return "Hello, World!";
}

return "Unknown: $name";
}
}

$greater = new Greater;

// This appropriately prints "Hello, World!"
echo($greater->hello);

// This reports "Notice: Undefined property: Greater::$hello
// in /path/to/file/greater.php on line 8"
echo($greater->hi);

?>

I am assuming this is to stop infinite loops, but it is also annoying when done intentionally.

<DatabasesError Reporting>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22