<?php
class MyClass
{
const CONSTANT = 'constant value';
function showConstant() {
echo self::CONSTANT . "99 \n <br>";
}
}
echo MyClass::CONSTANT . "1 \n <br>";
$classname = "MyClass";
echo $classname::CONSTANT . "2 \n <br>";
$class = new MyClass();
$class->showConstant();
echo $class::CONSTANT."3 \n";
?>
constant value1 constant value2 constant value99 constant value3
================================================
<?
class MyClass
{
const CONSTANT = 'Myclass';
function showConstant() {
echo self::CONSTANT . "1 class file \n <br>";
}
}
?>
--------------------------------------------------------------
<?
class MyClass2
{
const CONSTANT = 'class2 <br>';
function showConstant() {
echo self::CONSTANT . " 2 file class \n <br>";
}
}
?>
-------------------------------------------------------------
<?php
function __autoload($class_name) {
include $class_name . '.php';
}
$obj = new MyClass();
$obj ->showConstant();
$obj2 = new MyClass2();
$obj2 ->showConstant();
?>
==============================================================
|