php-general Digest 13 Jan 2011 09:13:34 -0000 Issue 7130
Topics (messages 310704 through 310725):
Re: Array Symbol Suggestion
310704 by: Per Jessen
310705 by: Donovan Brooke
310706 by: Ashley Sheridan
310707 by: Steve Staples
310708 by: sono-io.fannullone.us
310709 by: Ashley Sheridan
310710 by: Joshua Kehn
310711 by: Joshua Kehn
310712 by: Daniel Brown
310713 by: Michael Shadle
310714 by: Daniel Brown
310723 by: Per Jessen
310724 by: Per Jessen
Re: HTML errors
310715 by: Admin
310725 by: Pete Ford
projectpier
310716 by: Peter Lind
310717 by: Ashley Sheridan
310718 by: Peter Lind
310719 by: Camilo Sperberg
Closure and $this
310720 by: Raymond Irving
310721 by: Greg Bair
310722 by: Larry Garfield
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
[email protected] 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?
The php-development mailing list. What you're suggesting is a pretty
fundamental change, don't be disappointed if it is not met with
universal approval.
--
Per Jessen, Zürich (5.9°C)
--- End Message ---
--- Begin Message ---
[email protected] 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
Hi Marc,
I'm a PHP n00b as well and had similar thoughts regarding this..
just imagine two variables called the same thing.. a string and array..
and accidentally resetting one..
$oops = "something";
however, from my experience, there is often this kind of problem in
any language, and that is where naming conventions come in very handy.
I don't know if the PHP community has any standard convention.. but I
would suggest something like:
$a_foo (for arrays)
$f_foo (imploding into form variables)
$s_foo (string variables)
$db_foo (variables coming from databases perhaps)
etc..
This way, you'd never be confused of the origin of the variable.
Donovan
--
D Brooke
--- End Message ---
--- Begin Message ---
On Wed, 2011-01-12 at 11:45 -0800, [email protected] 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
--- End Message ---
--- Begin Message ---
On Wed, 2011-01-12 at 20:58 +0100, Per Jessen wrote:
> [email protected] 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?
>
> The php-development mailing list. What you're suggesting is a pretty
> fundamental change, don't be disappointed if it is not met with
> universal approval.
>
>
> --
> Per Jessen, Zürich (5.9°C)
>
>
not to mention, the @ symbol is a reserved character... an error control
character[1]. So I dont think that using that char, would work. I
dont see using it's own character to work at all, but in your own code,
you can use your own naming conventions to denote what is an array, and
what is a variable.
Good luck with your suggestion, I personally wouldn't like it (as I am
so used to the way it is now), but that is just me.
Steve.
[1] http://ca.php.net/manual/en/language.operators.errorcontrol.php
--- End Message ---
--- Begin Message ---
Thanks for all the responses to my suggestion. I realize this would be a major
change, so that's why I also mentioned it as an addition to the language.
I'm sure it's just what you're used to, but still being new to all this, it
just makes sense (to me anyway) to have different symbols for different
variable types:
$scalar
@array
#hash
Since the @ sign is already reserved, maybe there's another symbol that would
work better? I don't know. These are just ideas that I came up with while
reading and I thought I'd throw it out there to see what others thought.
I like the idea of a naming convention, so that's what I'll do in my scripts.
I also appreciate the heads up on is_string(), is_array(), and var_dump().
Thanks again,
Marc
--- End Message ---
--- Begin Message ---
On Wed, 2011-01-12 at 12:23 -0800, [email protected] wrote:
> Thanks for all the responses to my suggestion. I realize this would be a
> major change, so that's why I also mentioned it as an addition to the
> language.
>
> I'm sure it's just what you're used to, but still being new to all this, it
> just makes sense (to me anyway) to have different symbols for different
> variable types:
> $scalar
> @array
> #hash
>
> Since the @ sign is already reserved, maybe there's another symbol that would
> work better? I don't know. These are just ideas that I came up with while
> reading and I thought I'd throw it out there to see what others thought.
>
> I like the idea of a naming convention, so that's what I'll do in my scripts.
> I also appreciate the heads up on is_string(), is_array(), and var_dump().
>
> Thanks again,
> Marc
If you check out the manual pages for those functions as well, you'll
see other related functions. I must say, of any language I've used, the
php.net documentation is by far the best, giving plenty of information
and user comments too. It's a resource I still can't do without, and I
reckon even the old hands on this list would say the same.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Jan 12, 2011, at 3:23 PM, [email protected] wrote:
> Thanks for all the responses to my suggestion. I realize this would be a
> major change, so that's why I also mentioned it as an addition to the
> language.
>
> I'm sure it's just what you're used to, but still being new to all this, it
> just makes sense (to me anyway) to have different symbols for different
> variable types:
> $scalar
> @array
> #hash
>
> Since the @ sign is already reserved, maybe there's another symbol that would
> work better? I don't know. These are just ideas that I came up with while
> reading and I thought I'd throw it out there to see what others thought.
>
> I like the idea of a naming convention, so that's what I'll do in my scripts.
> I also appreciate the heads up on is_string(), is_array(), and var_dump().
>
> Thanks again,
> Marc
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
This would make sense to me for a compiled or strongly typed language, but no
other language (that I've know of) uses this format. I haven't used Perl.
In a dynamically typed language you normally have duck typed variables.
# Python
a = "Hello"
b = 12
// JavaScript
a = "Hello";
b = 12;
c = [1, 2, 3];
// PHP
$a = "Hello";
$b = 12;
$c = array(1, 2, 3);
Unless I'm misunderstanding the question?
Regards,
-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com
--- End Message ---
--- Begin Message ---
On Jan 12, 2011, at 3:28 PM, Ashley Sheridan wrote:
> If you check out the manual pages for those functions as well, you'll
> see other related functions. I must say, of any language I've used, the
> php.net documentation is by far the best, giving plenty of information
> and user comments too. It's a resource I still can't do without, and I
> reckon even the old hands on this list would say the same.
>
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
I fully agree with you on php.net being some of the best documentation out
there.
I would say that a lot of the Java documentation is wonderfully done as well.
It doesn't offer user comments, but it is very complete and covers just about
every aspect of a class.
Regards,
-Josh
____________________________________
Joshua Kehn | [email protected]
http://joshuakehn.com
--- End Message ---
--- Begin Message ---
On Wed, Jan 12, 2011 at 14:45, <[email protected]> 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?
The @ is an error control operator, used to buffer the output and
store it in a variable - $php_errormsg. There's no way that would be
changed to become an array designator (though that doesn't mean your
idea itself is a bad one).
> What is the proper channel for making suggestions like this?
Usually on the Internals mailing list ([email protected]) or
as a Feature Request in the bug tracker (http://bugs.php.net/).
--
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/
--- End Message ---
--- Begin Message ---
On Wed, Jan 12, 2011 at 12:37 PM, Daniel Brown <[email protected]> wrote:
> The @ is an error control operator, used to buffer the output and
> store it in a variable - $php_errormsg. There's no way that would be
> changed to become an array designator (though that doesn't mean your
> idea itself is a bad one).
@ squelches error messages.
AFAIK $php_errormsg is the last error that PHP incurred. not based on "@"
"@" just silences the errors from being reported, which is a "bad
thing" as error collection is done even if error_reporting is off, it
is still built internally as a string, that's why developing with
E_ALL and E_STRICT even on is the best practice. even notices wind up
adding to the internal error/etc. string stack.
--- End Message ---
--- Begin Message ---
On Wed, Jan 12, 2011 at 15:41, Michael Shadle <[email protected]> wrote:
> On Wed, Jan 12, 2011 at 12:37 PM, Daniel Brown <[email protected]> wrote:
>
>> The @ is an error control operator, used to buffer the output and
>> store it in a variable - $php_errormsg. There's no way that would be
>> changed to become an array designator (though that doesn't mean your
>> idea itself is a bad one).
>
> @ squelches error messages.
>
> AFAIK $php_errormsg is the last error that PHP incurred. not based on "@"
Correct. The way I worded it makes it sound like @ is what
populates the variable, which would be incorrect. Plus, I should also
mention that $php_errormsg is only available if you enable
track_errors anyway, which (if I remember correctly) is off by
default.
Thanks for pointing that out, Mike.
--
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/
--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
> On Wed, 2011-01-12 at 12:23 -0800, [email protected] wrote:
>
>> Thanks for all the responses to my suggestion. I realize this would
>> be a major change, so that's why I also mentioned it as an addition
>> to the language.
>>
>> I'm sure it's just what you're used to, but still being new to all
>> this, it just makes sense (to me anyway) to have different symbols
>> for different variable types: $scalar @array
>> #hash
>>
>> Since the @ sign is already reserved, maybe there's another symbol
>> that would work better? I don't know. These are just ideas that I
>> came up with while reading and I thought I'd throw it out there to
>> see what others thought.
>>
>> I like the idea of a naming convention, so that's what I'll do in my
>> scripts. I also appreciate the heads up on is_string(), is_array(),
>> and var_dump().
>>
>> Thanks again,
>> Marc
>
>
> If you check out the manual pages for those functions as well, you'll
> see other related functions. I must say, of any language I've used,
> the php.net documentation is by far the best, giving plenty of
> information and user comments too. It's a resource I still can't do
> without, and I reckon even the old hands on this list would say the
> same.
Yes, I wouldn't want to be without my local php.net mirror. Other
languages that can easily match the quality of the documentation -
assembler, C and C++, to name a few.
--
Per Jessen, Zürich (7.9°C)
--- End Message ---
--- Begin Message ---
Donovan Brooke wrote:
> however, from my experience, there is often this kind of problem in
> any language, and that is where naming conventions come in very handy.
>
> I don't know if the PHP community has any standard convention..
One popular naming convention:
http://en.wikipedia.org/wiki/Hungarian_notation
--
Per Jessen, Zürich (7.8°C)
--- End Message ---
--- Begin Message ---
If you are going to use double quotes escape out.
>> echo "<li><a href='index.php?page=".$category."'>".$replace."</a></li>";
On Jan 12, 2011, at 2:30 PM, tedd <[email protected]> wrote:
> At 10:35 PM -0500 1/11/11, David McGlone wrote:
>> Hi Everyone, I'm having a problem validating some links I have in a foreach.
>> Here is my code:
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>> "http://www.w3.org/TR/html4/loose.dtd">
>>
>> my PHP code:
>> $categorys = array('home', 'services', 'gallery', 'about_us', 'contact_us',
>> 'testimonials');
>> foreach($categorys as $category){
>> $replace = str_replace("_", " ", $category);
>> echo "<li><a href='index.php?page=$category'>$replace</a></li>";
>> }
>>
>> Validator Error:
>> an attribute value must be a literal unless it contains only name characters
>>
>> Šome>home</a></li><li><a href=index.php?page=services>services</a></li><li><a
>> hŠ
>>
>> I have tried various combinatons and different doctypes. I'm beginning to
>> wonder if this code is allowed at all.
>>
>>
>> --
>> Blessings
>> David M.
>
> David:
>
> First of all, the type (strict or transitional) of DOCTYPE doesn't matter --
> it only matters IF you are going to use deprecated HTML elements
> (transitional) or not (strict).
>
> Second, your <li> (i.e., list) should start with a "type of list" tag, such
> <ol> for ordered list -- there are several different types (i.e., ol, ul,
> dir, menu, dl dt dd).
>
> Third, you might try this:
>
> echo("<li><a href=\"index.php?page=$category\">$replace</a></li>");
>
> The Validator might be objecting to the way you use ' instead of ".
>
> HTH's
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
On 12/01/11 14:13, Richard Quadling wrote:
On 12 January 2011 14:07, Steve Staples<[email protected]> wrote:
On Wed, 2011-01-12 at 13:40 +0000, Richard Quadling wrote:
On 12 January 2011 13:20, Steve Staples<[email protected]> wrote:
Jim,
Not to be a smart ass like Danial was (which was brilliantly written
though), but you have your "example" formatted incorrectly. You are
using commas instead of periods for concatenation, and it would have
thrown an error trying to run your example. :)
# corrected:
echo "<li><a href=\"index.php?page={$category}\">{$replace}</a></li>";
Steve Staples.
Steve,
The commas are not concatenation. They are separators for the echo construct.
I don't know the internals well enough, but ...
echo $a.$b.$c;
vs
echo $a, $b, $c;
On the surface, the first instance has to create a temporary variable
holding the results of the concatenation before passing it to the echo
construct.
In the second one, the string representations of each variable are
added to the output buffer in order with no need to create a temp var
first.
So, I think for large strings, using commas should be more efficient.
Richard.
Well... I have been learned. I had no idea about doing it that way, I
apologize to you, Jim.
I guess my PHP-fu is not as strong as I had thought?
Thank you Richard for pointing out this to me, I may end up using this
method from now on. I have just always concatenated everything as a
force of habit.
Steve Staples.
I was never taught by nuns.
Eh? Oh I get it... (ugh!)
Surely PHP-fu is taught by monks?
--
Peter Ford, Developer phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd. www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS
--- End Message ---
--- Begin Message ---
Heads up: jeg har flyttet projectpier over paa fastaval.dk domaenet -
det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
(og dermed ikke logge ind det forkerte sted).
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
On Wed, 2011-01-12 at 23:14 +0100, Peter Lind wrote:
> jeg har flyttet projectpier over paa fastaval.dk domaenet -
> det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
> fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
> (og dermed ikke logge ind det forkerte sted)
I think perhaps your change in domains was not meant to be posted to the
list? :p
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
2011/1/12 Ashley Sheridan <[email protected]>
> On Wed, 2011-01-12 at 23:14 +0100, Peter Lind wrote:
>
> jeg har flyttet projectpier over paa fastaval.dk domaenet -
> det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
> fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
> (og dermed ikke logge ind det forkerte sted)
>
>
> I think perhaps your change in domains was not meant to be posted to the
> list? :p
>
>
There's a massive ooops! if ever I did see one. Sorry about the (unintended)
noise and thanks for letting me know.
--- End Message ---
--- Begin Message ---
At least now we all know of the domainname change xD
Sent from my iPhone
On 12-01-2011, at 19:38, Peter Lind <[email protected]> wrote:
> 2011/1/12 Ashley Sheridan <[email protected]>
>
>> On Wed, 2011-01-12 at 23:14 +0100, Peter Lind wrote:
>>
>> jeg har flyttet projectpier over paa fastaval.dk domaenet -
>> det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
>> fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
>> (og dermed ikke logge ind det forkerte sted)
>>
>>
>> I think perhaps your change in domains was not meant to be posted to the
>> list? :p
>>
>>
> There's a massive ooops! if ever I did see one. Sorry about the (unintended)
> noise and thanks for letting me know.
--- End Message ---
--- Begin Message ---
Hello,
Does anyone know if closures will ever support the $this keyword?
I think it would be very useful when working with objects.
Best regards__RaymondDo more with less - http://raxanpdi.com
--- End Message ---
--- Begin Message ---
On Wed, 12 Jan 2011 20:02:11 -0800 (PST)
Raymond Irving <[email protected]> wrote:
> Hello,
> Does anyone know if closures will ever support the $this keyword?
> I think it would be very useful when working with objects.
>
> Best regards__RaymondDo more with less - http://raxanpdi.com
>
Probably not, and my understanding of why comes from this line from the
docs (http://www.php.net/manual/en/functions.anonymous.php):
"Anonymous functions are currently implemented using the Closure class."
So, in other words, your closure does not belong to the class you
declare it in, but the Closure class.
Thus, if it supported the $this variable, it would refer not to the
class you want, but instead to the Closure class.
Just my understanding. If it's not right, someone point it out.
--
Greg Bair
PHP Developer
--- End Message ---
--- Begin Message ---
On Wednesday, January 12, 2011 11:37:19 pm Greg Bair wrote:
> On Wed, 12 Jan 2011 20:02:11 -0800 (PST)
>
> Raymond Irving <[email protected]> wrote:
> > Hello,
> > Does anyone know if closures will ever support the $this keyword?
> > I think it would be very useful when working with objects.
> >
> > Best regards__RaymondDo more with less - http://raxanpdi.com
>
> Probably not, and my understanding of why comes from this line from the
> docs (http://www.php.net/manual/en/functions.anonymous.php):
>
> "Anonymous functions are currently implemented using the Closure class."
>
> So, in other words, your closure does not belong to the class you
> declare it in, but the Closure class.
>
> Thus, if it supported the $this variable, it would refer not to the
> class you want, but instead to the Closure class.
>
> Just my understanding. If it's not right, someone point it out.
Actually at one point early on they did support a $this, but the way it was
bound to an object was half-assed and incomplete so it was removed entirely
from 5.3. The intent was to then properly think through how that binding
should happen and re-introduce it properly in 5.4. I believe a consensus was
reached on how that should happen but I'm not sure what its implementation
status is at present.
I believe this is the relevant RFC:
http://wiki.php.net/rfc/closures/object-extension
--Larry Garfield
--- End Message ---