<?php
class Author
{
private $name;
private $id;
public function __construct($id, $name = '')
{
$this->id = $id;
$this->name = $name;
}
public function name()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function id()
{
return $this->id;
}
}
class Post
{
private $id;
private $title;
private $body;
private $author;
public function __construct($id, $title, $body, $author)
{
$this->id = $id;
$this->title = $title;
$this->body = $body;
$this->author = $author;
}
public function id()
{
return $this->id;
}
public function title()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
}
public function author()
{
return $this->author;
}
public function setAuthor(Author $author)
{
$this->author = $author;
}
}
$post = new Post(111, 'A Song of Ice and Fire', 'My book is the shiz', new Author(222, 'George RR Martin'));
echo $post->author->name;
Fatal error: Uncaught Error: Cannot access private property Post::$author in /in/VEhSa:73
Stack trace:
#0 {main}
thrown in /in/VEhSa on line 73
Process exited with code 255.
Fatal error: Cannot access private property Post::$author in /in/VEhSa on line 73
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VEhSa on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VEhSa on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/VEhSa on line 5
Process exited with code 255.