← Forum
294 pts


Why are negative numbers not accepted?

Why isn't this working with negative numbers? Does PHP only know unsigned variables, where all Bits are used for positive numbers?

    $myName = "Cyrus";
    $myAge = -1;

Error: Did you create a variable called $myAge and set it equal to your age as a number? Don't forget your semicolon!

  • 286 pts


    2 votes

    PHP does work with negative numbers. Just that this exercise is looking for a positive number. Try setting $myAge = 1;, and it should work. And according to, "PHP does not support unsigned integers."

    • th3m3s about 2 years ago
      Thanks for your answer Garrett. Nice to know that there are no unsigned data types in PHP. Still IMO that the code does not accept negative integers is a bug, especially with that kind of error message. If the Eric Weinstein has intended that the user shall enter only positive numbers, he should have spared this for the lecture with conditional structures and accepted negative numbers in this lecture while giving a hint that the student will learn in a later lecture how to prevent this.
  • 1 pts


    0 votes

    I'm not sure why you would say this isn't working. This is perfectly legitimate code (I ran it on my machine to be sure). Did you get an error? Add the line

    echo $myage;

    to your code and it will show "-1" (no quotes).

Sign in to post to the forum.

Sign in