php 致命错误:函数名必须是一个字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11706528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php Fatal error: Function name must be a string in
提问by user1560466
Fatal error: Function name must be a string in /home/../public_html/updater.php on line 3
致命错误:函数名称必须是第 3 行 /home/../public_html/updater.php 中的字符串
1: <?php
2:
3: $user_id = $_GET("uid"); /* <-- Line 3 */
4: $user_name = $_GET("uname");
5: $setting = $_GET("setting");
6:
7: $MyString = $user_name + '[' + $user_id + ']{' + $setting + '} \n';
8:
9: $myfile = fopen('database.txt', 'a');
10: fwrite($myfile, $MyString . '\n');
11: fclose($myfile);
12:
13: ?>
What's the problem ?
有什么问题 ?
回答by Jake Lucas
Change your $_GET()code to $_GET[]with square brackets.
将您的$_GET()代码更改为$_GET[]使用方括号。
- $_GET is a superglobal (pre-defined/built-in variable), and not a function.
- http://php.net/manual/en/language.variables.superglobals.php
- $_GET 是一个超全局变量(预定义/内置变量),而不是一个函数。
- http://php.net/manual/en/language.variables.superglobals.php
回答by Tim S
In addition to using square brackets instead of parentheses, you should change line 7 to
除了使用方括号而不是圆括号之外,您还应该将第 7 行更改为
$MyString = $user_name . "[" . $user_id . "]{" . $setting . "} \n";
and line 10 to
和第 10 行到
fwrite($myfile, $MyString . "\n");
You should use a period (.) for string concatenation instead of a plus (+). Also, when writing special characters (newline), you need to use double quoted strings instead of single quoted.
您应该使用句点 (.) 代替加号 (+) 进行字符串连接。此外,在编写特殊字符(换行符)时,您需要使用双引号字符串而不是单引号。
回答by Musa
回答by Debashis
The syntax is wrong. Correct syntax is:
语法错误。正确的语法是:
$user_id = $_GET["uid"];
Apply the changes wherever applicable.
在适用的地方应用更改。
回答by Raiden
Confused why you are using two newlines. Shouldn't one be enough?
困惑为什么要使用两个换行符。一个不就够了吗?
Also your code is wrong with '\n', you can't do that.
此外,您的代码与 '\n' 有误,您不能这样做。
You need to;
你需要;
"\n" implicit newline that's properly interpreted (or chr(10))
正确解释的“\n”隐式换行符(或 chr(10))
CRLF (chr(13) + chr(10)) which is used for DOS formatted text files.
CRLF (chr(13) + chr(10)) 用于 DOS 格式的文本文件。
CR which is used for linux-formatted text files. (or chr(13))
CR 用于 linux 格式的文本文件。(或 chr(13))
Also, I would suggest using "ta" for the fopen call. Pulled from fopen() php page;
另外,我建议在 fopen 调用中使用“ta”。从 fopen() php 页面拉取;
You should use the 't' mode if you are working with plain-text files and you use \n to delimit your line endings in your script, but expect your files to be readable with applications such as notepad. You should use the 'b' in all other cases.
如果您正在处理纯文本文件并且使用 \n 来分隔脚本中的行尾,则应该使用 't' 模式,但希望您的文件可以通过记事本等应用程序读取。您应该在所有其他情况下使用“b”。
References:
参考:
http://php.net/manual/en/function.fopen.php
http://php.net/manual/en/function.fopen.php
http://www.december.com/html/spec/ascii.html(13 is considered carriage return or /r, 10 is considered newline or /n)
http://www.december.com/html/spec/ascii.html(13被认为是回车或 /r,10 被认为是换行符或 /n)

