简体   繁体   中英

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. Is it a IDE issue? 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. 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标记。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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