将常量值分配给php中的const错误 [英] Assigning const value to const error in php

查看:69
本文介绍了将常量值分配给php中的const错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
 class Lala {
  const a = "a";
  const b = a . "b";
 }
?>

解析错误:语法错误,意外的'(',期望','或';'在线4

Parse error: syntax error, unexpected '(', expecting ',' or ';' on line 4

这是什么问题?

推荐答案

从文档:


该值必须是常量表达式,而不是变量,属性,数学运算结果或

The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.

请参阅 http://www.php.net/manual/en/language.oop5.constants.php

这篇关于将常量值分配给php中的const错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆