PHP的错误,在成员初始化器串联在阵列() [英] PHP error, concatenation in array() in member initialiser

查看:140
本文介绍了PHP的错误,在成员初始化器串联在阵列()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误有以下code:

I'm getting an error with the following code:

public $arr = array('email' => 'admin@' . str_replace('http://', '', SERVER_ROOT));

Parse error: syntax error, unexpected '.', expecting ')' 

我是不是真的很傻?当然,我可以在这里连接字符串?

Am I being really stupid? Surely I can concatenate strings here?

这是在一个类中声明的变量。

This is a variable declared in a class.

推荐答案

您不能初始化类和前pression属性。你所要做的,在构造函数或使用固定的值,就像一个普通的字符串。

You cannot initialize class attributes with an expression. You have to do that in the constructor or use a fixed value, like a regular string.

这篇关于PHP的错误,在成员初始化器串联在阵列()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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