php - 传递给 myFunction() 的参数 1 必须是 string 的实例,string given, called in

标签 php string function arguments instance

我有这个功能:

function myFunction(string $name) {
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db(...); 

    $insertplayer="INSERT INTO `...`(....)
    VALUES (......')";
    if (!mysql_query($insertplayer,$db))
      {
      die('Error: ' . mysql_error());
      }
    $id = mysql_insert_id();
    echo 'done for player N°'.$id;
    mysql_close($db);
}

以及我使用的表格:

<form action="insertplayer.php" method="post">
    <input type="text" name="nameplayer" />
    <input type="submit" value="ok" />
</form>

但是当我这样做的时候,我有这个错误:

Catchable fatal error: Argument 1 passed to myFunction() must be an instance of string, string given, called in C:.... on line 23 and defined in C:...

我在 int 问题上遇到了这个错误。我该如何解决?

最佳答案

尝试从函数声明中删除原始数据类型。 PHP 不需要原始数据类型的类型提示。

function myFunction($name) {
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db(...); 

    $insertplayer="INSERT INTO `...`(....)
    VALUES (......')";
    if (!mysql_query($insertplayer,$db))
      {
      die('Error: ' . mysql_error());
      }
    $id = mysql_insert_id();
    echo 'done for player N°'.$id;
    mysql_close($db);
}

关于php - 传递给 myFunction() 的参数 1 必须是 string 的实例,string given, called in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384628/

相关文章:

c - 这段 C 代码的作用是什么? [与函数体代码混淆]

javascript - javascript对象中的访问器和普通函数有什么区别?

php - 如何使用 Php 删除查询字符串 URL 中的空字节?

java - 基于移位方向和空格数的凯撒密码移位Java

php - 数据透视表上的 laravel 一对多

java - Android - 写/读文件编码

string - Bash 测试正则表达式匹配,似乎总是返回 OK 即使不匹配

不使用随机模块的Python随机函数

PHP fputcsv编码

php - 从 PHP 页面运行 Shell 脚本