Good and Honest Host of the month, September 2008,
WSServers.com
Thank you for visiting this site. If you are looking for web hosting
services, you have come to the right place. Please search my database of
over 2400
hosting companies.
If you need any help, please email me at terence @ hostpulse.com . I
will personally try to reply your email within a day and give you some basic
guidelines, negotiate with a few hosts to offer you good pricing or
answer any hosting related problems that you may have.
In PHP 4, objects are compared in a very simple manner, namely: Two object
instances are equal if they have the same attributes and values, and are
instances of the same class. Similar rules are applied when comparing two
objects using the identity operator (===).
If we were to execute the code in the example below:
Example 17-1. Example of object comparison in PHP 4
<?php function bool2str($bool) { if ($bool === false) { return 'FALSE'; } else { return 'TRUE'; } }
function Flag($flag=true) { $this->flag = $flag; } }
class SwitchableFlag extends Flag {
function turnOn() { $this->flag = true; }
function turnOff() { $this->flag = false; } }
$o = new Flag(); $p = new Flag(false); $q = new Flag();
$r = new SwitchableFlag();
echo "Compare instances created with the same parameters\n"; compareObjects($o, $q);
echo "\nCompare instances created with different parameters\n"; compareObjects($o, $p);
echo "\nCompare an instance of a parent class with one from a subclass\n"; compareObjects($o, $r); ?>
We will see:
Compare instances created with the same parameters
o1 == o2 : TRUE
o1 != o2 : FALSE
o1 === o2 : TRUE
o1 !== o2 : FALSE
Compare instances created with different parameters
o1 == o2 : FALSE
o1 != o2 : TRUE
o1 === o2 : FALSE
o1 !== o2 : TRUE
Compare an instance of a parent class with one from a subclass
o1 == o2 : FALSE
o1 != o2 : TRUE
o1 === o2 : FALSE
o1 !== o2 : TRUE
Which is the output we will expect to obtain given the comparison rules
above. Only instances with the same values for their attributes and from the same
class are considered equal and identical.
Even in the cases where we have object composition, the same comparison
rules apply. In the example below we create a container class that stores
an associative array of Flag objects.
Example 17-2. Compound object comparisons in PHP 4
<?php class FlagSet { var $set;
function FlagSet($flagArr = array()) { $this->set = $flagArr; }
function addFlag($name, $flag) { $this->set[$name] = $flag; }
function removeFlag($name) { if (array_key_exists($name, $this->set)) { unset($this->set[$name]); } } }
$u = new FlagSet(); $u->addFlag('flag1', $o); $u->addFlag('flag2', $p); $v = new FlagSet(array('flag1'=>$q, 'flag2'=>$p)); $w = new FlagSet(array('flag1'=>$q));
echo "\nComposite objects u(o,p) and v(q,p)\n"; compareObjects($u, $v);
echo "\nu(o,p) and w(q)\n"; compareObjects($u, $w); ?>
Web Hosting Showcase
View the web hosting
showcase to find more relevant web hosting choice that will guide you in
selecting a good web hosting company.
This site provide
free reviews of web hosting services from 100 selected companies. There
are over 3000 over website hosting companies on the internet. Please
research these domain hosting services carefully before you sign up with
any. Read articles on web page hosting, web site hosting, domain names,
website speed test, cheap web hosting services, PHP scripts, mysql
database, asp hosting and virtual private server to gain a better
knowledge on domain hosting and cheap web hosting.