sKunKbad Posted July 8, 2015 Share Posted July 8, 2015 (edited) I've posted here because the set_value() function in the code below is exclusive to CodeIgniter. I've used ternary operators as array elements before, by simply wrapping them in parenthesis. What's confusing to me is that on my development environment, which is Ubuntu w/ PHP 5.5.X, everything works fine, but the production environment is some Linux hosting PHP 5.4.41, and it just gives a white screen. This happens without any error displayed, and happens even when the code is not executed, just simply loading the code (syntax error?). The code causing white screen: <?php $arr = [ 'a' => ( ! empty( set_value('a') ) ? date('Y-m-d', strtotime( set_value('a') ) ) : NULL ), 'b' => ( ! empty( set_value('b') ) ? date('Y-m-d', strtotime( set_value('b') ) ) : NULL ), 'c' => ( ! empty( set_value('c') ) ? date('Y-m-d', strtotime( set_value('c') ) ) : NULL ), 'd' => ( ! empty( set_value('d') ) ? date('Y-m-d', strtotime( set_value('d') ) ) : NULL ) ]; So, why would my development environment be OK with this code but production have a white screen of death? Edited July 8, 2015 by sKunKbad Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/ Share on other sites More sharing options...
scootstah Posted July 8, 2015 Share Posted July 8, 2015 White screen is generally a fatal error. Check the Apache error log. Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515889 Share on other sites More sharing options...
sKunKbad Posted July 8, 2015 Author Share Posted July 8, 2015 Error logs don't show anything. I can replicate this by running the following script: <?php function set_value($x) { return FALSE; } $arr = [ 'a' => ( ! empty( set_value('a') ) ? date('Y-m-d', strtotime( set_value('a') ) ) : NULL ), 'b' => ( ! empty( set_value('b') ) ? date('Y-m-d', strtotime( set_value('b') ) ) : NULL ), 'c' => ( ! empty( set_value('c') ) ? date('Y-m-d', strtotime( set_value('c') ) ) : NULL ), 'd' => ( ! empty( set_value('d') ) ? date('Y-m-d', strtotime( set_value('d') ) ) : NULL ) ]; var_dump( $arr ); On production I get the white screen of death. On development I get: array(4) { ["a"]=> NULL ["b"]=> NULL ["c"]=> NULL ["d"]=> NULL } Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515910 Share on other sites More sharing options...
scootstah Posted July 8, 2015 Share Posted July 8, 2015 Ah, I see you are doing $arr = [];. That syntax is new to PHP 5.4. What version are you running on your production? Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515913 Share on other sites More sharing options...
sKunKbad Posted July 8, 2015 Author Share Posted July 8, 2015 Ah, I see you are doing $arr = [];. That syntax is new to PHP 5.4. What version are you running on your production? 5.4.41 Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515916 Share on other sites More sharing options...
scootstah Posted July 8, 2015 Share Posted July 8, 2015 After putting your code in my IDE, it alerted me to the following: "Arbitrary expressions in empty are allowed in PHP 5.5 only". Until PHP 5.5, you cannot evaluate functions inside of empty(). You can only use a variable. 1 Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515917 Share on other sites More sharing options...
sKunKbad Posted July 8, 2015 Author Share Posted July 8, 2015 Cool, thanks for the answer. It would be nice if PHP would have at least spit out some kind of an error. Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515927 Share on other sites More sharing options...
scootstah Posted July 9, 2015 Share Posted July 9, 2015 It should have. Your error reporting settings are probably not set up properly on your production config. Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515930 Share on other sites More sharing options...
sKunKbad Posted July 9, 2015 Author Share Posted July 9, 2015 I tried: error_reporting(E_ALL); ini_set("display_errors", 1); Still nothing, just white screen. Nothing logged. Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515941 Share on other sites More sharing options...
scootstah Posted July 9, 2015 Share Posted July 9, 2015 It's because the error is occurring before that code is executed. I'm betting that errors are turned off in your php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/297229-codeigniter-ternary-operator-as-array-element-causing-white-screen/#findComment-1515968 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.