CKTIS / PHP
Komentarze i dokumentacja
Komentarz liniowy zaczyna // lub #, a blokowy otaczają /* i */.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
// line comment
/* block comment */
/** documentation comment */Komentarz liniowy zaczyna // lub #, a blokowy otaczają /* i /. Bloków nie można zagnieżdżać. Dokumentację /* przed deklaracją odczyta refleksja, jeśli środowisko zachowało komentarze. W PHP 8 #[ rozpoczyna atrybut.
/** 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]
Przykłady
<?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")]);
Wynik
[25,true]