This forum is now read-only. Please use our new forums at

Introduction to PHP Forum

View Course » View Exercise

294 points
Submitted by
about 5 years ago

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!

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."

299 points
Submitted by
about 5 years ago

1 Comment

508dfc9df2d6800200006da7_672213073 th3m3s about 5 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.

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).

1 point
Submitted by
about 5 years ago