“非法偏移类型”突然出现在注册数组 Laravel 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24897320/
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
'Illegal Offset Type" suddenly occurring in registration array Laravel
提问by user2480176
In my registration store function which is called after the user has typed in valid information I have a default array that is converted to JSON and stored in my DB with the user. All of a sudden I am getting the error:
在用户输入有效信息后调用的注册存储函数中,我有一个默认数组,该数组被转换为 JSON 并与用户一起存储在我的数据库中。突然间我收到错误消息:
Illegal Offset Type (line 50)
which the last object of my first array (it is multi dimensional). I deleted the object to see if the error was specific to that object but the error still persists. I don't understand where this error is coming from because I did't change anything in or around the registration system for a while.
这是我的第一个数组的最后一个对象(它是多维的)。我删除了该对象以查看错误是否特定于该对象,但错误仍然存在。我不明白这个错误是从哪里来的,因为我有一段时间没有改变注册系统内部或周围的任何东西。
This is the store() function being called after the registration form is submitted:
这是提交注册表后调用的 store() 函数:
public function store()
{
$input = Input::only('username', 'email', 'password', 'password_confirmation');
$this->registrationForm->validate($input);
$user = User::create($input);
$arr = array(
[1] => array(
'name' => 'Apple',
'time' => '2:00 am',
'date' => '10.26.96',
'symptom' => false,),
[2] =>array(
'name' => 'Banana',
'time' => '3:56 pm',
'date' => '10.26.96',
'symptom' => false,),
[3] =>array(
'name' => Input::get('symptom'),
'time' => '4:45 pm',
'date' => '10.26.96',
'symptom' => true,
));
$user->json = json_encode($arr);
$user->save();
Auth::login($user);
return Redirect::home();
}
The error occurs in "line 50" which is in the last object of the first array 'symptom' => false,),
错误发生在第一个数组的最后一个对象中的“第 50 行” 'symptom' => false,),
I have absolultley no idea how this happened. I even used time machine to load my project from a few days ago when I am certain it was fully functional and the error is still there. I will appreciate any help, please let me know if more information is needed.
我绝对不知道这是怎么发生的。我什至使用时间机器从几天前加载我的项目,当时我确定它功能齐全并且错误仍然存在。我将不胜感激,如果需要更多信息,请告诉我。
回答by zerkms
array
initialization syntax only accept key names as a plain scalar values, thus having ['foo']
syntax is incorrect in this case.
array
初始化语法只接受键名作为普通标量值,因此['foo']
在这种情况下语法是不正确的。