Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the <a href="http://de2.php.net/manual/en/language.oop5.properties.php" rel="noreferrer">PHP manual on class properties</a> (emphasis mine):</p> <blockquote> <p>Class member variables are called "properties". You may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration <strong>may include an initialization, but this initialization must be a constant value</strong> --that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. </p> </blockquote> <p>Either create it inside the constructor (<a href="http://en.wikipedia.org/wiki/Object_composition" rel="noreferrer">composition</a>)</p> <pre><code>class Foo { protected $bar; public function __construct() { $this-&gt;bar = new Bar; } } </code></pre> <p>or <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="noreferrer">inject</a> it in the constructor (<a href="http://en.wikipedia.org/wiki/Object_composition#Aggregation" rel="noreferrer">aggregation</a>) </p> <pre><code>class Foo { protected $bar; public function __construct(Bar $bar) { $this-&gt;bar = $bar; } } </code></pre> <p>or use setter injection.</p> <pre><code>class Foo { protected $bar; public function setBar(Bar $bar) { $this-&gt;bar = $bar } } </code></pre> <p>You want to <a href="http://en.wikipedia.org/wiki/Design_Patterns" rel="noreferrer">favor aggregation over composition</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload