0
<?php
    /*if(isset($_COOKIE["telcoProvider"])) {
        $telcoProvider = $_COOKIE["telcoProvider"];

    } else {
        $telcoProvider = "NOT FOUND";
    }*/

    $telcoProvider = isset($_COOKIE["telcoProvider"]) ? $_COOKIE["telcoProvider"] : "NOT FOUND".

    print "<p>Your telecommunication company is <b>$telcoProvider.</b></p>";
?>

I have checked the browser and the Cookie is there.

It works with the normal if-else, but not with the ternary operator. It does not proceed to the print, yet, it does not display any error either.

What am I missing?

2
  • 1
    You have a typo, you need to finish your statement with ;, not with a dot. Commented Apr 7, 2015 at 8:34
  • 2
    My pinky is short. :p Commented Apr 7, 2015 at 8:48

1 Answer 1

2
$telcoProvider = isset($_COOKIE["telcoProvider"]) ?
 $_COOKIE["telcoProvider"] : "NOT FOUND".
                                        ^

What's that dot (.) doing there instead of a ; ?

I wonder why Eclipse did not say anything?

Try this and you will get to an answer to that question :) Note the dot before print

$test= 1==1? "Oh nice no print :P " : "Oh" . print("Really?");
var_dump($test);
Sign up to request clarification or add additional context in comments.

1 Comment

Eclipse didn't say anything because it's perfectly valid PHP, just not what you wanted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.