示例#1
0
    echo __NAMESPACE__ . PHP_EOL;
    // output namespace
    echo __LINE__ . PHP_EOL;
    // output file line number
    class MyClass
    {
        public function __construct()
        {
            echo __CLASS__ . PHP_EOL;
        }
        public function myMethod()
        {
            echo __METHOD__ . PHP_EOL;
        }
    }
    function myFunction()
    {
        echo __FUNCTION__ . PHP_EOL;
    }
    $myClass = new MyClass();
    // output Classname
    $myClass->myMethod();
    // output Method
    myFunction();
    // output Function
}
namespace {
    // Global
    var_dump(__NAMESPACE__);
    // output empty on Global Scope
}
示例#2
0
 *  cppclassinphp.php
 *  @author Jasper van Eck<*****@*****.**>
 * 
 *  An example file to show the working of using a C++ class in PHP.
 */
class TestClass
{
    public $x = 1223;
    public function __construct()
    {
        echo "TestClass::__construct\n";
    }
}
//create a MyCustomClass object, which is an object of a C++ class
$object1 = new MyClass();
$object2 = $object1->myMethod(1);
$object2->myMethod(1);
echo "unset\n";
unset($object1);
echo "got here\n";
return;
//echo("prop x: ".$object1->x."\n");
$object1->x = 10;
$object1->y = 20;
echo "prop x: " . $object1->x . "\n";
echo "prop y: " . $object1->y . "\n";
$object2 = clone $object1;
echo "prop x: " . $object2->x . "\n";
echo "prop y: " . $object2->y . "\n";
return;
// run a function of the class
示例#3
0
{
    public function __construct()
    {
        var_dump('construct');
    }
    public function myMethod()
    {
        return 'myMethod()';
    }
    public function __destruct()
    {
        var_dump('destruct');
    }
}
$oMyClass = new MyClass();
var_dump($oMyClass->myMethod());
class Person
{
    private $name;
    private $age;
    private $id;
    function __construct($name, $age)
    {
        $this->name = $name;
        $this->age = $age;
    }
    function setId($id)
    {
        $this->id = $id;
    }
    function __destruct()