简体   繁体   English

抽象类中PHP方法的文档

[英]Documentation of PHP methods in the abstract class

Is it possible to make a method documentation on the abstract method and whoever extends it inhered the documentation also? 是否可以在抽象方法上制作方法文档,而扩展它的人也可以继承该文档? Example: 例:

<?php
abstract class Math{
    /**
     * Method that receive two values and return the result of some operation.
     * @param $a Number
     * @param $b Number
     */
    abstract public function values($a, $b);
}
?>

<?php
class Sum extends Math{
    /**
     * @return $a+$b;
     */
    public function values($a, $b){
        return $a+$b;
    }
}
?>

<?php
class Divide extends Math{
    /**
     * @return $a/$b;
     * @throws Exception.
     */
    public function values($a, $b){
        if($b != 0){
            return $a/$b;
        }else{
            throw new Exception("Impossible to divide by 0.");
        }
    }
}
?>

How do I put all those informations about the method together? 如何将有关该方法的所有这些信息放在一起? Currently, I work with Netbeans 7.1. 目前,我正在使用Netbeans 7.1。 Is it a IDE issue? 这是IDE问题吗? Or is it just not how this works? 还是不是这样呢?

<?php
// Estabele conexão com o MySQL
$connect = mysql_connect('localhost', 'root', '123456') or die('A conexão falhou.');
// Seleciona o banco de dados
$database = mysql_select_db('monografia', $connect) or die('Falha ao tentar selecionar banco de dados.');

if ($database)
    echo 'Conectado atraves do driver nativo.';

?>

<br />

<?php
class Conexao {
    protected $conexao;
    public function Conexao() {
        $this->conexao = new MySQLi('localhost', 'root', '123456', 'monografia', 3306);
        if (!$this->conexao->connect_error)
            echo 'Conectado atraves da extensao MySQLi.';
    }
}
new Conexao();

?>

<br />

<?php
class ConexaoPDO {
    protected $pdo;    
    public function ConexaoPDO() {
        try {
            $this->pdo = new PDO('mysql:host=localhost:3306;dbname=monografia', 'root', '123456', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
            echo 'Conectado atraves do PDO.';
        } catch(PDOException $e) {
            echo $e->getMessage();
        }
    }
}

new ConexaoPDO();
?>

That would be specific to the tool/ide/plug-in being used. 这将特定于所使用的工具/ IDE /插件。 As far as common practices go, I have never seen inherited documentation. 就常规做法而言,我从未见过继承的文档。 In any case, just think about how much better the clarity will be for others reading your code if you put the full documentation in for each class, inherited, abstracted or otherwise. 无论如何,只要考虑为每个类(继承,抽象或其他)放置完整的文档,其他人阅读您的代码的清晰度将提高多少。

我建议您查看@inheritDoc标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM