<?php
trait common{
function shout(){
return 'hello world!';
}
}
class a{
use common;
}
class b{
use common;
}
if(trait_exists('common')) {
echo (new a())->shout();
}
if(trait_exists('common')) {
echo (new b())->shout();
}
trait_exists
(No hay información de versión disponible, podría estar únicamente en SVN)
trait_exists — Comprobar si el trait existe
Descripción
bool trait_exists
( string
$traitname
[, bool $autoload
] )
Parámetros
-
traitname -
Nombre del trait a comprobar
-
autoload -
Si aplicar la autocarga si no está ya cargado.
Valores devueltos
Devuelve TRUE si el trait existe, FALSE si no, NULL en caso de error.
mr dot ryansilalahi at gmail dot com ¶
10 days ago
