Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Luc de Brouwer
seal-mask
.a{fill-rule:evenodd;}techdegree
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 Points

What is the outcome of this simple question? (Loose types)

I went to a developers meetup for PHP and I had to answer the following question that is particularly interesting because of it exposures how PHP works which I would like to share with the community.

What will be the output?

<?php 

if ( "10" == "1e1")
{
   print "pass";
}

else
{
 print "no pass";
}

?>

1 Answer

Hey, Thank you for sharing this with the community, it made me work my mind and look up this new information. if I understand it well, "1e1" is the mathematic notation for 10, so php compare it as equal. same goes for

"10*10" == "1e2"

Luc de Brouwer
seal-mask
.a{fill-rule:evenodd;}techdegree
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 Points

Yes, that is true. Because of loose types in PHP, the compiler will interpret "10" and "1e1" as an integer value so 1e1 would be 1 ^ 1 = 10 so the if evaluates to true and thus will print "pass".

Many people, including my teacher's which have over 20+ years of coding, said that it would evaluate to no pass because they didn't think of loose types in PHP but when I told them 1e1 is the notation for 10, they looked at me and said Aaahhh, now I get it. It made me think differently about PHP and its power.

LoL, indeed, thats why I say, you can be so good at smthg, but you can never know it all. there is always smthg more to learn. thank you again for the share.