Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Extending a class is something you only want to do when you can say class <code>categories</code> is a class <code>Base</code>. Something like that sort of utility class you have their is almost always the wrong way to go. PHP also has introduced something called <a href="http://php.net/manual/en/language.oop5.traits.php">traits</a> for copy/paste code. However my personal preference is that it is something you will never want to use, because it tightly couples the traits to your class, which is something you want to avoid.</p> <p>See for more information the <a href="http://en.wikipedia.org/wiki/Liskov_substitution_principle">Liskov Substitution principle</a> in <a href="http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29">SOLID programming</a>.</p> <p>If it was up to me I would avoid those magic getters / setters either way and just add your own getters / setters methods to the class.</p> <p>The mistake about some base class isn't something only you are doing (hell even I have done it in the past). Think about some class <code>Database</code> and a class <code>Article</code>. Because the <code>Article</code> class needs access to the database many people let the class extend the <code>Database</code> class. This isn't correct because an article isn't an database. Instead an instance of the database class should be injected into the article class by using <a href="http://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a>. The instance should either be injected into the class constructor (if all or many methods need access to it) or just the methods that need it. So when extending a class you have to be able to say class B is a class A.</p> <p>Some other notes about your code:</p> <ul> <li>Always make your class names PascalCase. This is not really required to make your code work, but it follows a <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md">naming convention often used</a>.</li> <li>And my personal preference a bit: please always add curly braces to your foreach statements. It is more clear what is happening when other people are reading your code.</li> </ul>
    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