i got this class:
class Trajectory{
private $points = array();
public function __construct(){
}
public function addPoint(Point $myPoint){
$this->points[] = $myPoint; // line 20
}
}
when i try to run the method addPoint(), I'm getthing this error:
( ! ) Fatal error: Using $this when not in object context in /index.php on line 20
I tried changing it to:
$points[] = $myPoint;
but then the Trajectory's $point array doesn't change, instead its creating a new $points array each time i use the addPoint method.
You could not call this method as static method.
You should call it on an instance of the Class.
$trajectory = new Trajectory();
$trajectory->addPoint($point);
Instead of Trajectory::addPoint($point);