laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.13k stars 10.87k forks source link

Rendering a variable inside of JSON which is inside a script tag in a blade layout section causes Array to string conversion stack trace #754

Closed dcarrith closed 11 years ago

dcarrith commented 11 years ago

I'm using a custom reCAPTCHA widget and want to pass in the language that's currently in use. I have a view which defines a blade section and then yields it in a layout. When I try to use a variable inside of JSON which is inside of a script tag, I get a nasty Array to string conversion error.

@section('content')

<script type="text/javascript" charset="utf-8"> var RecaptchaOptions = { theme: "custom", lang: "{{ $recaptcha_lang }}" }; custom_theme_widget: "recaptcha_widget" </script> ... @stop

Taking the variable out gets rid of the error:

@section('content')

<script type="text/javascript" charset="utf-8"> var RecaptchaOptions = { theme: "custom", lang: "english" }; custom_theme_widget: "recaptcha_widget" </script> ... @stop

Here's the stack trace:

ErrorException: Notice: Array to string conversion in /var/www/musxc.com/htdocs/app/storage/views/a19f020bba55806642b788a150d9a773 line 5

in /var/www/musxc.com/htdocs/app/storage/views/a19f020bba55806642b788a150d9a773 line 5
at ErrorHandler->handle('8', 'Array to string conversion', '/var/www/musxc.com/htdocs/app/storage/views/a19f020bba55806642b788a150d9a773', '5', array('__path' => '/var/www/musxc.com/htdocs/bootstrap/../app/storage/views/a19f020bba55806642b788a150d9a773', '__data' => array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'environment' => 'development', 'debug' => null, 'base_protocol' => null, 'secure_protocol' => null, 'base_domain' => null, 'site_title' => null, 'back_i18n' => 'Back', 'home_i18n' => 'Home', 'scroll_up_i18n' => 'Scroll Up', 'scroll_down_i18n' => 'Scroll Down', 'meta_description_content_i18n' => 'Stream your music collection to your device or remotely control your MPDTunes music server. You can listen to your music anytime, anywhere, and on any device.', 'theme_id' => '1', 'theme_bars' => 'a', 'theme_buttons' => 'a', 'theme_body' => 'a', 'theme_controls' => 'a', 'theme_action' => 'a', 'theme_active' => 'a', 'theme_alert' => 'r', 'theme_icon_class' => 'ui-icon-alt', 'ga_property_id' => '', 'google_site_verification_code' => '', 'mode' => 'streaming', 'crossfade' => '0', 'volume_fade' => '0', 'default_page_transition' => 'slide', 'default_dialog_transition' => 'slidedown', 'default_alert_transition' => 'pop', 'default_home_transition' => 'flow', 'home_link_data_ajax' => 'true', 'home_link' => '/', 'show_album_count_bubbles' => true, 'show_album_track_count_bubbles' => true, 'show_playlist_track_count_bubbles' => true, 'recaptcha_public_key' => array(), 'recaptcha_lang' => array(), 'first_name_i18n' => 'First Name', 'last_name_i18n' => 'Last Name', 'username_i18n' => 'Email (Username)', 'password_i18n' => 'Password', 'password_confirm_i18n' => 'Password Confirm', 'submit_i18n' => 'Submit', 'cancel_i18n' => 'Cancel', 'refresh_captcha_i18n' => 'Refresh', 'switch_type_audio_i18n' => 'Audio', 'switch_type_image_i18n' => 'Image', 'show_captcha_help_i18n' => 'Help', 'recaptcha_challenge_i18n' => 'reCAPTCHA Challenge', 'enter_the_two_words_above_i18n' => 'Enter the two words seen above', 'enter_the_numbers_you_hear_i18n' => 'Enter the numbers you hear'), '__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'environment' => 'development', 'debug' => null, 'base_protocol' => null, 'secure_protocol' => null, 'base_domain' => null, 'site_title' => null, 'back_i18n' => 'Back', 'home_i18n' => 'Home', 'scroll_up_i18n' => 'Scroll Up', 'scroll_down_i18n' => 'Scroll Down', 'meta_description_content_i18n' => 'Stream your music collection to your device or remotely control your MPDTunes music server. You can listen to your music anytime, anywhere, and on any device.', 'theme_id' => '1', 'theme_bars' => 'a', 'theme_buttons' => 'a', 'theme_body' => 'a', 'theme_controls' => 'a', 'theme_action' => 'a', 'theme_active' => 'a', 'theme_alert' => 'r', 'theme_icon_class' => 'ui-icon-alt', 'ga_property_id' => '', 'google_site_verification_code' => '', 'mode' => 'streaming', 'crossfade' => '0', 'volume_fade' => '0', 'default_page_transition' => 'slide', 'default_dialog_transition' => 'slidedown', 'default_alert_transition' => 'pop', 'default_home_transition' => 'flow', 'home_link_data_ajax' => 'true', 'home_link' => '/', 'show_album_count_bubbles' => true, 'show_album_track_count_bubbles' => true, 'show_playlist_track_count_bubbles' => true, 'recaptcha_public_key' => array(), 'recaptcha_lang' => array(), 'first_name_i18n' => 'First Name', 'last_name_i18n' => 'Last Name', 'username_i18n' => 'Email (Username)', 'password_i18n' => 'Password', 'password_confirm_i18n' => 'Password Confirm', 'submit_i18n' => 'Submit', 'cancel_i18n' => 'Cancel', 'refresh_captcha_i18n' => 'Refresh', 'switch_type_audio_i18n' => 'Audio', 'switch_type_image_i18n' => 'Image', 'show_captcha_help_i18n' => 'Help', 'recaptcha_challenge_i18n' => 'reCAPTCHA Challenge', 'enter_the_two_words_above_i18n' => 'Enter the two words seen above', 'enter_the_numbers_you_hear_i18n' => 'Enter the numbers you hear')) in /var/www/musxc.com/htdocs/app/storage/views/a19f020bba55806642b788a150d9a773 line 5
at include('/var/www/musxc.com/htdocs/app/storage/views/a19f020bba55806642b788a150d9a773') in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 15814
at PhpEngine->evaluatePath('/var/www/musxc.com/htdocs/bootstrap/../app/storage/views/a19f020bba55806642b788a150d9a773', array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'environment' => 'development', 'debug' => null, 'base_protocol' => null, 'secure_protocol' => null, 'base_domain' => null, 'site_title' => null, 'back_i18n' => 'Back', 'home_i18n' => 'Home', 'scroll_up_i18n' => 'Scroll Up', 'scroll_down_i18n' => 'Scroll Down', 'meta_description_content_i18n' => 'Stream your music collection to your device or remotely control your MPDTunes music server. You can listen to your music anytime, anywhere, and on any device.', 'theme_id' => '1', 'theme_bars' => 'a', 'theme_buttons' => 'a', 'theme_body' => 'a', 'theme_controls' => 'a', 'theme_action' => 'a', 'theme_active' => 'a', 'theme_alert' => 'r', 'theme_icon_class' => 'ui-icon-alt', 'ga_property_id' => '', 'google_site_verification_code' => '', 'mode' => 'streaming', 'crossfade' => '0', 'volume_fade' => '0', 'default_page_transition' => 'slide', 'default_dialog_transition' => 'slidedown', 'default_alert_transition' => 'pop', 'default_home_transition' => 'flow', 'home_link_data_ajax' => 'true', 'home_link' => '/', 'show_album_count_bubbles' => true, 'show_album_track_count_bubbles' => true, 'show_playlist_track_count_bubbles' => true, 'recaptcha_public_key' => array(), 'recaptcha_lang' => array(), 'first_name_i18n' => 'First Name', 'last_name_i18n' => 'Last Name', 'username_i18n' => 'Email (Username)', 'password_i18n' => 'Password', 'password_confirm_i18n' => 'Password Confirm', 'submit_i18n' => 'Submit', 'cancel_i18n' => 'Cancel', 'refresh_captcha_i18n' => 'Refresh', 'switch_type_audio_i18n' => 'Audio', 'switch_type_image_i18n' => 'Image', 'show_captcha_help_i18n' => 'Help', 'recaptcha_challenge_i18n' => 'reCAPTCHA Challenge', 'enter_the_two_words_above_i18n' => 'Enter the two words seen above', 'enter_the_numbers_you_hear_i18n' => 'Enter the numbers you hear')) in /var/www/musxc.com/htdocs/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php line 45
at CompilerEngine->get('/var/www/musxc.com/htdocs/app/config/../views/register.blade.php', array('__env' => object(Environment), 'app' => object(Application), 'errors' => object(MessageBag), 'environment' => 'development', 'debug' => null, 'base_protocol' => null, 'secure_protocol' => null, 'base_domain' => null, 'site_title' => null, 'back_i18n' => 'Back', 'home_i18n' => 'Home', 'scroll_up_i18n' => 'Scroll Up', 'scroll_down_i18n' => 'Scroll Down', 'meta_description_content_i18n' => 'Stream your music collection to your device or remotely control your MPDTunes music server. You can listen to your music anytime, anywhere, and on any device.', 'theme_id' => '1', 'theme_bars' => 'a', 'theme_buttons' => 'a', 'theme_body' => 'a', 'theme_controls' => 'a', 'theme_action' => 'a', 'theme_active' => 'a', 'theme_alert' => 'r', 'theme_icon_class' => 'ui-icon-alt', 'ga_property_id' => '', 'google_site_verification_code' => '', 'mode' => 'streaming', 'crossfade' => '0', 'volume_fade' => '0', 'default_page_transition' => 'slide', 'default_dialog_transition' => 'slidedown', 'default_alert_transition' => 'pop', 'default_home_transition' => 'flow', 'home_link_data_ajax' => 'true', 'home_link' => '/', 'show_album_count_bubbles' => true, 'show_album_track_count_bubbles' => true, 'show_playlist_track_count_bubbles' => true, 'recaptcha_public_key' => array(), 'recaptcha_lang' => array(), 'first_name_i18n' => 'First Name', 'last_name_i18n' => 'Last Name', 'username_i18n' => 'Email (Username)', 'password_i18n' => 'Password', 'password_confirm_i18n' => 'Password Confirm', 'submit_i18n' => 'Submit', 'cancel_i18n' => 'Cancel', 'refresh_captcha_i18n' => 'Refresh', 'switch_type_audio_i18n' => 'Audio', 'switch_type_image_i18n' => 'Image', 'show_captcha_help_i18n' => 'Help', 'recaptcha_challenge_i18n' => 'reCAPTCHA Challenge', 'enter_the_two_words_above_i18n' => 'Enter the two words seen above', 'enter_the_numbers_you_hear_i18n' => 'Enter the numbers you hear')) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 15578
at View->getContents() in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 15561
at View->render() in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 16869
at Response->setContent(object(View)) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 15901
at Response->__construct(object(View)) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 7365
at Router->prepare(object(View), object(Request)) in /var/www/musxc.com/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Controllers/Controller.php line 156
at Controller->processResponse(object(Router), 'getIndex', object(View)) in /var/www/musxc.com/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Controllers/Controller.php line 126
at Controller->callAction(object(Application), object(Router), 'getIndex', array()) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 7052
at Router->Illuminate\Routing\{closure}()
at call_user_func_array(object(Closure), array()) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 13313
at Route->callCallable() in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 13292
at Route->run(object(Request)) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 7072
at Router->dispatch(object(Request)) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 947
at Application->dispatch(object(Request)) in /var/www/musxc.com/htdocs/bootstrap/compiled.php line 935
at Application->run() in /var/www/musxc.com/htdocs/public/index.php line 49
dcarrith commented 11 years ago

It turns out that the $recaptcha_lang variable was null. After I set it, the Array to string conversion error went away. Since I'm porting an existing application from CodeIgniter, I could have sworn that variable WAS defined. I guess I deleted too much stuff from the controller while migrating that file to Laravel. I'll close the issue since it was user error.