For the third access method, I get an error locally.
哥特
哥特 2018-05-02 22:11:09
0
1
1240

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


哥特
哥特

reply all(1)
哥特

<?php

header("Content-type: text/html; charset=utf-8");

class demo{

const siteName = 'php中文网';

const domain = <<< 'EOT'

<a href="javascript:;">www.php.cn</ 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();

?>


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template