标签:des io ar java for sp div on cti
Support for object orientation was completely new to PHP 4, and was therefore not very sophisticated in comparison to the OO support in other languages, such as Java. When assigning variables, it was absolutely necessary not to make copies of GTK objects, but to pass references.
//PHP 4: copy as default behavior $a = new GtkLabel(); $a->set_text(‘1‘); $b = $a; $b->set_text(‘2‘); echo $a->get();//still 1 |
//PHP 4: making references $a = new GtkLabel(); $a->set_text(‘1‘); $b = &$a; $b->set_text(‘2‘); echo $a->get();//is 2 now |
//PHP 4: reference on instantiation $a = &new GtkLabel(); |
With PHP 5, things have changed: pass-by-reference is the default behavior now - one doesn‘t need the ampersand any more! The following script works under PHP 5 with PHP-GTK 2, without any problems:
<?php //PHP5: no Ampersand any more $a = new GtkLabel(); $a->set_text(‘1‘); $b = $a; $b->set_text(‘2‘); echo $a->get_text();//is 2 ?> |
The same applies for callbacks: no ampersand any more! Whereas you had to do the following under PHP 4 and GTK 1:
$window->connect_object(‘destroy‘, array(&$object, ‘function‘)); |
$window->connect_simple(‘destroy‘, array($object, ‘function‘)); |
Object References (the Ampersand &)
标签:des io ar java for sp div on cti
原文地址:http://www.cnblogs.com/huaziking/p/4066379.html