加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

类中PHP公共函数的顺序是否会影响其执行?

发布时间:2020-12-13 22:13:56 所属栏目:PHP教程 来源:网络整理
导读:我一直在关注这个 Symfony教程.在某些部分中,它只是告诉我在类中添加一个公共函数,但它没有说我是否应该在类的开头或结尾添加它. 例如: /** * JobeetCategory * * This class has been auto-generated by the Doctrine ORM Framework * * @package jobeet *
我一直在关注这个 Symfony教程.在某些部分中,它只是告诉我在类中添加一个公共函数,但它没有说我是否应该在类的开头或结尾添加它.

例如:

/**
 * 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);
  }
}

getActiveJObs公共函数是本教程中第一个显示的,countActiveJobs是我根据教程添加的最后一个函数.

一个类中的公共函数的顺序是否重要?

解决方法

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

不,它没有.该课程作为一个整体进行评估;方法的顺序无关紧要.

因此,虽然它没有任何约束力,但我遇到的最常见的订单,以及我最喜欢的订购方法是,

class ClassName 
 {

  - Variable definitions

  - Class constants

  - Constructor 

  - Public methods

  - Destructor (if needed)

  - Magic functions (if needed)

  - Private / helper methods

  }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读