Регистрация Войти
Войти через VK Войти через FB Войти через Google Войти через Яндекс
Войти через VK Войти через FB Войти через Google Войти через Яндекс
Поиск по сайту
if (!defined('__MAGIC_CONSTANT__')) {
// FAIL! even if __MAGIC_CONSTANT__ is defined,
// defined('__MAGIC_CONSTANT__') will ALWAYS return (bool)false.
}
3
david at thegallagher dot net ¶1 year ago
echo (defined('__DIR__') ? '__DIR__ is defined' : '__DIR__ is NOT defined' . PHP_EOL);
echo (defined('__FILE__') ? '__FILE__ is defined' : '__FILE__ is NOT defined' . PHP_EOL);
echo (defined('PHP_VERSION') ? 'PHP_VERSION is defined' : 'PHP_VERSION is NOT defined') . PHP_EOL;
echo 'PHP Version: ' . PHP_VERSION . PHP_EOL;
1
php at kennel17 dot co dot uk ¶6 years ago
function get_class_static() {
$bt = debug_backtrace();
if (isset($bt[1]['object']))
return get_class($bt[1]['object']);
else
return $bt[1]['class'];
}
2
Anonymous ¶1 year ago
trait PeanutButter {
function traitName() {echo __TRAIT__;}
}
trait PeanutButterAndJelly {
use PeanutButter;
}
class Test {
use PeanutButterAndJelly;
}
(new Test)->traitName(); //PeanutButter
0
skoobiedu at gmail dot com ¶19 days ago
// ensure the __DIR__ constant is defined for PHP 4.0.6 and newer
(@__DIR__ == '__DIR__') && define('__DIR__', realpath(dirname(__FILE__)));
0
raat1979 at gmail dot com ¶3 months ago
if(!defined(__DIR__)){
//will not work
}
0
chris dot kistner at gmail dot com ¶2 years ago
class base_class
{
function say_a()
{
echo "'a' - said the " . __CLASS__ . "<br/>";
}
function say_b()
{
echo "'b' - said the " . get_class($this) . "<br/>";
}
}
class derived_class extends base_class
{
function say_a()
{
parent::say_a();
echo "'a' - said the " . __CLASS__ . "<br/>";
}
function say_b()
{
parent::say_b();
echo "'b' - said the " . get_class($this) . "<br/>";
}
}
$obj_b = new derived_class();
$obj_b->say_a();
echo "<br/>";
$obj_b->say_b();
0
claude at NOSPAM dot claude dot nl ¶9 years ago
Note that __CLASS__ contains the class it is called in; in lowercase. So the code:
class A
{
function showclass()
{
echo __CLASS__;
}
}
class B extends A
{
}
$a = new A();
$b = new B();
$a->showclass();
$b->showclass();
A::showclass();
B::showclass();
results in "aaaa";
Смотрите также:
Описание на ru2.php.net
Описание на php.ru