note 121107 deleted from language.constants.predefined by peehaa

From: Date: Mon, 22 May 2017 07:28:13 +0000
Subject: note 121107 deleted from language.constants.predefined by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209090@lists.php.net to get a copy of this message
Note Submitter: fouzan786 at gmail dot com ---- Magic Constants Example1: <?php class classfz { function functionf() { echo "'Magic constant Function - current function name' : " .__FUNCTION__. "<br/>"; } function method() { echo "'Magic constant Method - current method name' : " .__METHOD__. "<br/>"; } function classf() { echo "'Magic constant Class - current class name' : " . __CLASS__ . "<br/>"; } function line() { echo "'Magic constant Line - current line no' : " . __LINE__ . "<br/>"; } } $obj=new classfz; $obj->functionf(); $obj->method(); $obj->classf(); $obj->line(); trait traitf { function traitName() {echo "'Magic constant Trait - current trait name' : " . __TRAIT__ . "<br/>";} } trait traitfz { use traitf; } class Test { use traitfz; } (new Test)->traitName(); require('constructor.php'); // i have this file in htdocs folder. you must have any file ,in that file you are only echo using. echo "'Magic constant File - current file name' : " . realpath(dirname(__FILE__)) . "<br />"; echo "'Magic constant Directory - current directory name' : " . __DIR__ . "<br />"; ?> Example:2 <?php //local name space namespace def{ class xyz { public function __construct() { echo "'Magic constant NAMESPACE - current namespace name' : " . __NAMESPACE__ . "<br />"; } } $obj=new xyz(); echo "<br />"; echo "'Magic constant NAMESPACE - current namespace name' : " . __NAMESPACE__ . "<br />"; } ?>

« previous php.notes (#209090) next »