Re: Array Symbol Suggestion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2011-01-12 at 11:45 -0800, sono-io@xxxxxxxxxxxxx wrote:

> I'd like to make a suggestion for a change, or possibly an addition, to the PHP language.
> 
> I'm learning PHP and have been very excited with what it can do in relation to HTML.  But when I got to the part about arrays, I was disappointed to see that they are designated with a $ the same as other variables.  I was learning Perl before I switched, and it uses the @ sign to designate an array.  That makes it a lot simpler to see at a glance what is an array and what isn't - at least for beginners like me.
> 
> Has there been any talk of adopting the @ sign for arrays in PHP?  Or is that symbol used for something else that I haven't read about yet?
> 
> What is the proper channel for making suggestions like this?
> 
> Thanks,
> Marc


PHP is a loosely typed language, so you can have a variable that,
throughout its lifetime in an app, is both a scaler (integer, string,
etc) or an array. For example:

<?php
$message = "hello world";

echo $message;

$message = array('hello', 'bob');
echo "{$message[0]} {$message[1]}";
?>

There are functions you can use to determine the type of a variable,
such as is_string() and is_array() and you can use var_dump() in debug
statements to quickly see the type of a variable. I think changing
something as integral as a variable prefix would break a lot of code
which makes use of the loose typing, and would cause much more confusion
further down the line.

Also, as you may have guessed, the @ symbol is already in use at the
moment. In PHP it ensures that minor errors are silently ignored. For
example:

@executeSomeFunction()

would run that named function, but ignore any minor errors and warnings.
You'll typically find it used a lot in calls to mail() as that can be
flaky on some systems due to a number of factors outside of PHP.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux