I have just started learning PHP, and here’s my first doubt…
Both of these work:
<?php
$function1 = "Aahan";
print "Hi, $function1";
?>
and
<?php
$function2 = Aahan;
print "Hi, $function2";
?>
See the difference? In the second example I didnt use the “” (quotation marks) for the variable string. But it still works.
Also, the stupid author of the book (which I wont name), uses “” in some examples and doesnt use them in some, without explanation. So, what should I think? Either way is okay or what do you advise?
EDIT: Sorry guys, the author is a good one. I misunderstood this string $x = 3;, and started checking out the above examples. Just realized that constants don’t need quotes. Sorry again.
EDIT-2: it doesn’t show me any error like you all have mentioned. How do I make it show the errors? or is it something wrong with my server itself? (I dont think so)
Aahan,
Is the right method for php. Its a string of chareters. Refer to php strings.
Now when you do
Php searches for a constant Aahan and when its not defined it treats it as a string. To explain further. Consider these:
And
While the first one with ” “(quotes) is right. The 2nd one gives you a syntax error.
This is the warning gernerated, unless you have turned it off
EDIT: To turn on comprehensive Error reporting Add the following code to the first line of your code.