/** * Create an object of class aSimilarClass that has similar contents to the * receiver. * * 'as' seems to be a reserved word, so 'asA' is used instead. * * @param string $aSimilarClass * @return object * @access public * @since 5/5/05 */ function &asA($aSimilarClass) { $obj =& SObject::newFrom($aSimilarClass, $this); return $obj; }
function test_new_from() { $octopus = new OctopusObject(); $dog = SObject::newFrom('DogObject', $octopus); $this->assertEqual($dog->numberOfLegs, 8); $this->assertEqual($dog->numberOfTails, 1); $props = get_object_vars($dog); $this->assertFalse(in_array('numberOfSuckers', $props)); // Same class $octopus->numberOfLegs = 20; $octopus->numberOfSuckers = 100; $octopus2 = SObject::newFrom('OctopusObject', $octopus); $this->assertEqual($octopus2->numberOfLegs, 20); $this->assertEqual($octopus2->numberOfSuckers, 100); $props = get_object_vars($octopus2); $this->assertEqual(count($props), 2); }