note 117423 added to language.oop5.constants

From: Date: Tue, 09 Jun 2015 08:43:36 +0000
Subject: note 117423 added to language.oop5.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-202781@lists.php.net to get a copy of this message
<?php //http://php.net/manual/en/language.oop5.constants.php /** * Constant name shouldn't start with $ * Constant name may lower or uppercases. * Same constant name can be used as a property name but must start with $ symbol. * Constant doesn't available with $this-> inside class definition. * Constant is available with self:: inside class definition. * Constant can't call with $this-> outside class. * Constant is accessible with :: after "Class Name or Object". * */ class MyClass { // Parse error: syntax error, unexpected '$CONSTANT' (T_VARIABLE), expecting identifier (T_STRING) in constant.php //const $CONSTANT = 'constant named "CONSTANT" '; const CONSTANT = 'constant named "CONSTANT" '; const small = 'constant named "small" '; public $small = 'SAME CONTSNAT NAME AS PROPERTIES.'; //Fatal error: Cannot redefine class constant MyClass::small in constant.php // const small = 'constant named "small" '; function showConstant() { echo self::CONSTANT . "<br>"; //echo $this->CONSTANT . "<br>"; // Notice: Undefined property: MyClass::$CONSTANT in constant.php } } $class = new MyClass(); $class->showConstant(); //Notice: Undefined property: MyClass::$CONSTANT in constant.php //echo $class->CONSTANT."<br>"; echo $class->small."<br>"; // SAME CONTSNAT NAME AS PROPERTIES. ?> ---- Server IP: 72.52.91.14 Probable Submitter: 122.174.251.176 ---- Manual Page -- http://php.net/manual/en/language.oop5.constants.php Edit -- https://master.php.net/note/edit/117423 Del: integrated -- https://master.php.net/note/delete/117423/integrated Del: useless -- https://master.php.net/note/delete/117423/useless Del: bad code -- https://master.php.net/note/delete/117423/bad+code Del: spam -- https://master.php.net/note/delete/117423/spam Del: non-english -- https://master.php.net/note/delete/117423/non-english Del: in docs -- https://master.php.net/note/delete/117423/in+docs Del: other reasons-- https://master.php.net/note/delete/117423 Reject -- https://master.php.net/note/reject/117423 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202781) next »