Does the order of public PHP functions in a class influence its execution?

I followed this symfony . In some sections, he simply tells me to add public functioninside class, but he does not say whether 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 open function getActiveJObswas first shown in the textbook, and the countActiveJobslast function that I added in accordance with the textbook.

Does the order of social functions within a class mean?

+3
source share
3 answers

Does the order of social functions within a class mean?

No, it is not. The class is evaluated as a whole; the order of the methods does not matter.

, , , , -

class ClassName 
 {

  - Variable definitions

  - Class constants

  - Constructor 

  - Public methods

  - Destructor (if needed)

  - Magic functions (if needed)

  - Private / helper methods

  }
+18

:-) , .

. , . , , . . . . , . , . .

, , , , .

, , . , , , , . , .

- :

class MyClass
{
    const MY_CONSTANT_ONE
    const MY_CONSTANT_TWO

    public $myPublicVariableONe
    public $myPublicVariableTwo
    protected $_myProtectedVariableOne
    private $_myPrivateVariableOne
    private $_myPrivateVariableTwo

    public function DoSomeOfficialStuff()
    {
        $this->_myNicePrivateMethodOne();
    }

    private myNicePrivateMethodOne(){
    }

    public function returnSomeOfficialStuff()
    {
        $this->_myNicePrivateMethodTwo();
    }

    myNicePrivateMethodTwo(){
    }
}
+1

There are no answers. Functions will be called elsewhere and not executed from top to bottom. It doesn't matter if countActiveJobs is at the top of the class or at the bottom.

0
source

Source: https://habr.com/ru/post/1758894/


All Articles