echo '3.Object::Class constant name:'.(new demo)::siteName.'<br>';
Error message:
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';' in E:\web\phpstudy\WWW\class\oopself.php on line 18
php version is 5.4
<?php
header("Content-type: text/html; charset=utf-8");
class demo{
const siteName = 'php中文网';
const domain = <<< 'EOT'
<a href="javascript:;">m.sbmmt.com</ a>
EOT;
public function getSiteName(){
return self::siteName;
}
//Method 1: Class name: Class constant name.
echo '1.Class name::Class constant name'.demo::siteName.demo::domain.'<br>';
//Method 2: Class variable: Class constant name must be run in PHP5.3 or above.
$className = 'demo';
echo '2. Class variable::Class constant name:'.$className::siteName.'<br>';
//Method 3: Use the object of the current class to access class constants.
//Method 4: Use the method of strangulation to access class constants indirectly.
echo '4.Object->Method():'.(new demo)->getSiteName();
?>
<?php
header("Content-type: text/html; charset=utf-8");
class demo{
const siteName = 'php中文网';
const domain = <<< 'EOT'
<a href="javascript:;">m.sbmmt.com</ a>
EOT;
public function getSiteName(){
return self::siteName;
}
}
//Method 1: Class name: Class constant name.
echo '1.Class name::Class constant name'.demo::siteName.demo::domain.'<br>';
//Method 2: Class variable: Class constant name must be run in PHP5.3 or above.
$className = 'demo';
echo '2. Class variable::Class constant name:'.$className::siteName.'<br>';
//Method 3: Use the object of the current class to access class constants.
echo '3.Object::Class constant name:'.(new demo)::siteName.'<br>';
//Method 4: Use the method of strangulation to access class constants indirectly.
echo '4.Object->Method():'.(new demo)->getSiteName();
?>