php - 如何修复从函数返回的 NULL,错误在哪里?
问题描述
我想使用函数返回一个静态字符串,但没有返回
这个函数需要返回“I am” 那么错误在哪里呢?首先我尝试回显没有返回然后打印,print_r 最后也没有返回 var_export 或 var_dump 返回 NULL
// Here is the function
function w_is_the_error() {
global $where;
return $where;
}
// I executed here
$the_error = w_is_the_error($where = 'I Am');
// When doing var_export it returns NULL
var_export($the_error);
解决方案
因为这不是您发送或接受函数参数的方式。
function w_is_the_error($where) {
return $where;
}
// I executed here
$the_error = w_is_the_error('I Am');
// When doing var_export it returns NULL
var_export($the_error);
global
是拐杖。不要使用它,使用参数。
推荐阅读
- c - 如何在 C 中直观地为着色器制服插入字符串?
- flutter - Flutter AdMob 适用于 Android,但不适用于 iOS
- python - python % 运算符是否损坏
- ffmpeg - ffmpeg 错误:无法为 'scale=1500:1000' 找到合适的输出格式
- kotlin - 如果有条件如何正确满足
- javascript - 为什么我的 MySQL 函数总是“未定义”?
- django - Django 模型自相关子级别
- node.js - 无法将打字稿类正确加载到反应项目中
- pandas - 为什么 Pandas DataFrame 组或切片会过时?它们是副本吗?
- javascript - Javascript可以被欺骗相信一个对象是一个数组吗?