База знанияИзпитен център
BGБългарски
Избери език13

CKTIS / PHP

Коментари и документация

// или # започва едноредов коментар, а /* и */ ограждат блок.

Версия: PHP 8.4; repository runtime, production runtime not attested

Синтаксис

// line comment
/* block comment */
/** documentation comment */

// или # започва едноредов коментар, а /* и / ограждат блок. Блокове не се влагат. Документация /* пред декларация се чете чрез рефлексия, ако коментарите са запазени. В PHP 8 #[ започва атрибут.

/** Unit price in cents. */
function unitPrice():int { /* in cents */ return 25; } // no output here
$doc=(new ReflectionFunction("unitPrice"))->getDocComment(); echo json_encode([unitPrice(),str_contains($doc,"cents")]);
[25,true]

Примери

<?php
/** Unit price in cents. */
function unitPrice():int { /* in cents */ return 25; } // no output here
$doc=(new ReflectionFunction("unitPrice"))->getDocComment(); echo json_encode([unitPrice(),str_contains($doc,"cents")]);

Резултат

[25,true]

Източници