name = $inArr[0]; $this->street = ""; $this->city = $inArr[1]; $this->state = $inArr[2]; $this->zip = ""; break; case 5: $this->name = $inArr[0]; $this->street = $inArr[1]; $this->city = $inArr[2]; $this->state = $inArr[3]; $this->zip = $inArr[4]; break; default: throw new Exception("$arrLength parameters not supported"); } } public function display(){ echo "

Address Entry

\n"; echo "

\n"; echo "Name: " . $this->name . "
\n"; echo "Street: " . $this->street . "
\n"; echo "City: " . $this->city . "
\n"; echo "State: " . $this->state . "
\n"; echo "Zip: " . $this->zip . "
\n"; echo "

\n"; } // Automatic Getters and Setters function __call($method, $arguments) { $prefix = strtolower(substr($method, 0, 3)); $property = strtolower(substr($method, 3)); if (empty($prefix) || empty($property)) { return; } if ($prefix == "get" && isset($this->$property)) { return $this->$property; } if ($prefix == "set") { $this->$property = $arguments[0]; } } } ?> PHP Address Object

PHP Address Object

Create an object and display it.

display(); ?>

Change the object contents and display them.

setName("Jane Doe"); echo "

New name is: " . $anAddress->getName() . "

\n"; $anAddress->setCity("Los Angeles"); echo "

New city is: " . $anAddress->getCity() . "

\n"; $anAddress->setState("CA"); echo "

New state is: " . $anAddress->getState() . "

\n"; $anAddress->display(); ?> display(); // This throws exception $anAddress2 = new Address(array("John Doe", "New York")); $anAddress2->display(); ?>