Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can't Use Function Return Value In Write Context.
  • I'm working on notifications. Whenever there are something that should be notified to user, a "flash session" is created. It's retrieved in view if it exist.
    I I do like this...
    <?php
    
     if ( !empty( Session::get_flash( 'error' ) ) ) {
    
      echo '<div id="error">' . Session::get_flash( 'error' ) . '</p>';
    
     }
    
    ?>
    

    ...I get error. I could do like this...
    <?php
    
     $error = Session::get_flash( 'error' );
    
     if ( !empty( $error ) ) {
    
      echo '<div id="error">' . Session::get_flash( 'error' ) . '</p>';
    
     }
    
    ?>
    

    ...but I'm searching for better ways. I don't need unnecessary variable unless there is any better way! Any ideas, guys?
  • How about just:
    if (Session::get_flash( 'error' ))
    {
    

    It will return null if not set so that should be enough. If you want to be precise, you could go with:
    if (Session::get_flash( 'error' ) !== null)
    {
    
  • Thanks, cahva. Didn't think about it... )
  • empty() is not a function, it's a language construct. You can't use that on the result value of a function.
  • I'm pretty sure that empty() is a function and goes under variable handling functions. Look at php.net.
  • "Note: Because this is a language construct and not a function, it cannot be called using variable functions"

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion