class Point { var $x, $y; function Point( $x, $y ) { $this->x = $x; $this->y = $y; } //No accessors because we directly do it. function distance_from_origin() { return $this->distance_from_point( new Point(0,0) ); } function distance_from_point( $p ) { return sqrt( ($this->x - $p->x)*($this->x - $p->x) + ($this->y - $p->y)*($this->y - $p->y) ); } } $a = new Point(3,4); $b = new Point(11,10); print $a->distance_from_origin() . "\n"; print $a->distance_from_point($b) . "\n";