Re: reporting errors when $ sign is missing in front of a variable
| From: | Haluk Karamete | Date: | Thu, 12 Jan 2012 05:17:48 +0000 |
| Subject: | Re: reporting errors when $ sign is missing in front of a variable | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316264@lists.php.net to get a copy of this message | ||
Thanks...
Well I just changed the <?php error_reporting (E_ALL ^ E_NOTICE); ?>
to <?php error_reporting (E_ALL ); ?> and that does it for me.
Notice: Use of undefined constant my_age - assumed 'my_age' in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 40
my_age
Now back in business :)
Notice: Use of undefined constant my_age - assumed 'my_age' in
D:\Hosting\5291100\html\blueprint\bp_library.php on line 40my_age
On Wed, Jan 11, 2012 at 9:12 PM, Tommy Pham <tommyhp2@gmail.com> wrote:
> On Wed, Jan 11, 2012 at 8:43 PM, Haluk Karamete <halukkaramete@gmail.com> wrote:
>>
>> Hi, I'm coming from ASP background.
>> There, there is a life saver option called "option explicit". It
>> forces you to declare your variables using the "dim" statement. The
>> good thing about that is that if you were to mis-spell one of your
>> variables, asp.dll throws an error stating that on line so and so,
>> variable so and so not declared. This allows you to immediately fix
>> the error saving lots of time. If you did not use "option explicit",
>> then that misspelled variable would not have caused any error and you
>> woud have spent much more time debugging your app as to what went
>> wrong where.
>>
>> Now, I undersand with PHP, that we do not have a variable declaration
>> per se; you put a $ sign in front of a word, and that becomes a
>> variable. Since in asp, we do not use $ much. I keep forgetting that.
>> I first declare a var and set a value for it using the $. But then I
>> refer to the darned thing, without the $. And there are no errors. Ths
>> behaviour seems extremely odd to me.
>>
>> How do I achieve the functionality that if I forget to use $ sign for
>> a previously declared variable, php throws me an error.
>>
>> example
>>
>> $my_var = 90;
>> echo my_var;
>>
>> I want an error to be thrown in line 2. what do I need to do?"
>> I was assuming that since there is no function titled "my_var", PHP
>> would have complain right there and then. But instead, it simply
>> echoes "my_var".
>>
>> I would have expected "my_var" to be outputted only if I were to write
>> echo "my_var";. This beats me.
>>
>> At the top of my page, I already have this <?php error_reporting
>> (E_ALL ^ E_NOTICE); ?>
>>
>> Haluk
>>
>>
>
> This works for me in development environment without a debugger setup
> using a web browser (note that I'm using 5.4RC2 so the default
> behavior of error_reporting(E_ALL) is different [1]:
>
> Notice: Use of undefined constant my_var - assumed 'my_var' in
> F:\dev\sites\wwwroot\php_apps\test.php on line 5
> my_var <?php
> error_reporting(E_ALL);
> ini_set('display_errors', 'on');
> $my_var = 90;
> echo my_var;
>
> highlight_file(__FILE__);
>
> Good luck,
> Tommy
>
> [1] http://php.net/function.error-reporting