Jump to content

[CodeIgniter] Ternary Operator as array element causing white screen


sKunKbad

Recommended Posts

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 by sKunKbad
Link to comment
Share on other sites

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 comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.