On Wed, Jan 11, 2012 at 8:43 PM, Haluk Karamete <halukkaram...@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
ini_set('display_errors', 'on');
$my_var = 90;
echo my_var;


Good luck,

[1] http://php.net/function.error-reporting

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to