I am following a tutorial on PHP. The code given below is to get the pages listed in the database to display to the webpage. I already fixed the problem and the code works fine.
When I used a NULL value for both variables, the $getSubj would work, and display the subject in the content page. $getPage would default to "Select A Subject or Page to Edit...". In the tutorial, of course, it worked.
I attempted to change the value to '' but that gave me an error. I changed it to " ". That failed as well. Finally, I tried ' ', and this worked. After two days of puzzling, and wonderment, I was able to move on. I changed both the value for $getPage & $getSubj for consistency. PHP doesn't seem to mind.
My question is why did ' ' finally do the trick, whereas NULL, "" and '' all failed? Why did PHP initially behave the way it did prior to replacing the values? BTW, '' is two single quotes with no space. Thank you in advance for your feedback.
Here is the function:
PHP Code:
function funcFndAll()
{
global $getSubj;
global $getPage;
Hi Wanna! Great suggestion but it didn't work. My code still did the same thing. But thank you for bringing that to my attention. I never would have caught that. Much appreciated!
I'm not so sure about null being case sensitive.. true and false certainly aren't..
The difference between null and '' is basically that '' is a string thats been initialised but it is empty. In other words the string has been created but it holds nothing.
Null means the string, object, whatever doesn't exist. If you tested $Var and it was null it basically means that $Var doesn't actually exist.
If thats still not quite clear, let me put it like this:
You can have a plastic container full of sweets. Thats your variable containing something.
You can have an empty container. Thats your ''
You can have no container. Thats your null.
Make sense? - You know that the container could theoretically exist (even if it doesn't) so you can test for it by testing it against null.
Also you're using ' ' in your code. ' ' is not the same as ''. ' ' contains a space character which although prints nothing on the screen it is a valid ASCII character so its not the same as an empty string.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
I'm not so sure about null being case sensitive.. true and false certainly aren't..
The difference between null and '' is basically that '' is a string thats been initialised but it is empty. In other words the string has been created but it holds nothing.
Null means the string, object, whatever doesn't exist. If you tested $Var and it was null it basically means that $Var doesn't actually exist.
If thats still not quite clear, let me put it like this:
You can have a plastic container full of sweets. Thats your variable containing something.
You can have an empty container. Thats your ''
You can have no container. Thats your null.
Make sense? - You know that the container could theoretically exist (even if it doesn't) so you can test for it by testing it against null.
Also you're using ' ' in your code. ' ' is not the same as ''. ' ' contains a space character which although prints nothing on the screen it is a valid ASCII character so its not the same as an empty string.
So with ' ' I am testing for something, whereas NULL is nothing. By swapping out the values I was basically telling PHP check for something...that may come later on...is that right? If I left it at NULL I am telling PHP to test for nothing?
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.
The biggest thing to remember is that null represents a void value of \0 regardless of datatype provided; however, null != '' (and also, != ' ' which is a string with a space in it) which differentiates between an initialized string of nothing and a variable of no value. Null is not case sensitive as it is neither a variable or a constant.
In the above situation, what you would actually have is:
PHP Code:
$a = null; // var dump will provide NULL or \0 $a = ''; // var dump will provide string(0), which equates to {''} $a = 'hello world'; // var dump will provide string(11), which equates to {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd') // C does not contain a datatype for a string, it is only a char array.
Also, an understanding of null is critical in OOP.