I've been following this Symfony tutorial. In some sections it just tells me to add a public function inside a class but it doesn't say if I should add it at the beginning or at the end of the class.

For instance:

/**
 * JobeetCategory
 *
 * This class has been auto-generated by the Doctrine ORM Framework
 *
 * @package    jobeet
 * @subpackage model
 * @author     Your name here
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class JobeetCategory extends BaseJobeetCategory
{
  public function countActiveJobs()
  {
    $q = Doctrine_Query::create()
      ->from('JobeetJob j')
      ->where('j.category_id = ?', $this->getId());

    return Doctrine_Core::getTable('JobeetJob')->countActiveJobs($q);
  }

  public function getSlug()
  {
    return Jobeet::slugify($this->getName());
  }

  public function getActiveJobs($max = 10)
  {
    $q = Doctrine_Query::create()
      ->from('JobeetJob j')
      ->where('j.category_id = ?', $this->getId())
      ->limit($max);

    return Doctrine_Core::getTable('JobeetJob')->getActiveJobs($q);
  }
}

The getActiveJObs public function was the first shown in the tutorial and countActiveJobs is the last function I added according to the tutorial.

Does the order of the public functions inside a class matter?

Accepted Answer

Does the order of the public functions inside a class matter?

Nope, it doesn't. The class is evaluated as a whole; the order of methods is not relevant.

So while it's in no way binding, the most common order I've encountered, and my favourite of ordering methods is, is

class ClassName 
 {

  - Variable definitions

  - Class constants

  - Constructor 

  - Public methods

  - Destructor (if needed)

  - Magic functions (if needed)

  - Private / helper methods

  }
Written by Pekka
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki