sKunKbad 17 Posted July 8, 2015 Share Posted July 8, 2015 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? Link to post Share on other sites
scootstah 104 Posted July 8, 2015 Share Posted July 8, 2015 White screen is generally a fatal error. Check the Apache error log. Link to post Share on other sites
sKunKbad 17 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 } Link to post Share on other sites
scootstah 104 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? Link to post Share on other sites
sKunKbad 17 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 Link to post Share on other sites
scootstah 104 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. Link to post Share on other sites
sKunKbad 17 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. Link to post Share on other sites
scootstah 104 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. Link to post Share on other sites
sKunKbad 17 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. Link to post Share on other sites
scootstah 104 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. Link to post Share on other sites
Recommended Posts
Archived
This topic is now archived and is closed to further replies.