php-general Digest 12 Jun 2010 09:23:52 -0000 Issue 6794

Topics (messages 306055 through 306071):

Re: is <?= good?
        306055 by: tedd
        306056 by: tedd
        306057 by: David Harkness
        306058 by: Daevid Vincent
        306059 by: Daevid Vincent
        306060 by: tedd
        306061 by: tedd
        306062 by: Ashley M. Kirchner
        306063 by: David Harkness
        306064 by: Ashley M. Kirchner
        306065 by: Ahmed Mohsen
        306067 by: Ahmed Mohsen
        306068 by: Daevid Vincent
        306069 by: Simon J Welsh
        306070 by: Robert Cummings

Why is there HTML in the error_log output? Please make it stop.
        306066 by: Daevid Vincent
        306071 by: Peter Lind

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
At 1:34 AM +0300 6/11/10, Ahmed Mohsen wrote:
I know that i should use the full open tag in php <?php ?> but i want to know if its good to use this tag <?=$name?> instead of <?php echo $name ?>

Ahmed:

In many cases it boils down to an individual preference. I am sure you will find programmers on both sides and in the middle of this argument. Some saying they never use it, others saying that they always use it, and still others saying "It depends" -- meaning they use it in certain cases.

I believe, just because it can be done doesn't mean that it should be done.

My practice is *never* to use <?=

In fact, my practice is to not only use <?php echo, but to enclose the echo argument with a (), like:

<?php echo("The answer is $answer");?>

I am sure there will be some that think that my practice is an overkill, or not "good practice", but it's a good thing that we all have a choice. Make your choice to best serve how you want your code to look.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 5:53 PM -0700 6/10/10, Daevid Vincent wrote:
I use them ALL the time. MUCH cleaner IMHO than the alternatives.

And *IF* someday it is ever depricated, it's trival to:

         s/<?=/<? echo/g

Don't let 'em scare ya!


 s/<?=/<?php echo/g

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Fri, Jun 11, 2010 at 11:16 AM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:

> For <?= to work, the short_tags setting needs to be turned on I believe,
> which can cause issues when outputting the XML declaration line unless
> it's broken into two parts, which is messier than '<?php echo' IMHO.
>

Can you give an example of how this breaks? I don't see any problems with

    <?= '<?xml blah blah ?>' ?>

unless you are trying to validate your PHP script as XML. Given that PHP is
*not* XML I don't know why you'd want to do that. But I've seen this
argument a few times while looking into this issue so maybe I'm just not
seeing the big picture.

David

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: tedd [mailto:tedd.sperl...@gmail.com] 
>
> I believe, just because it can be done doesn't mean that it 
> should be done.
> 
> My practice is *never* to use <?=
> 
> In fact, my practice is to not only use <?php echo, but to enclose 
> the echo argument with a (), like:
> 
> <?php echo("The answer is $answer");?>
> 
> I am sure there will be some that think that my practice is an 
> overkill, or not "good practice", but it's a good thing that we all 
> have a choice. Make your choice to best serve how you want your code 
> to look.

As per http://us3.php.net/echo

echo() is not actually a function (it is a language construct), so you are
not required to use parentheses with it. echo() (unlike some other language
constructs) does not behave like a function, so it cannot always be used in
the context of a function. Additionally, if you want to pass more than one
parameter to echo(), the parameters must not be enclosed within
parentheses. 

So you might want to reconsider your coding practice/style here and use the
construct as designed or you might end up with a far worse scenario than
short-tags could ever provide. Something more along the Python "print"
debacle.

Also, for the love of God, please don't embed a variable into a literal
string and use preprocessing.

Do it like so:

<?php echo 'The answer is '.$answer; ?>


--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: David Harkness [mailto:davi...@highgearmedia.com] 
> Sent: Friday, June 11, 2010 1:13 PM
> To: PHP General
> Subject: Re: [PHP] is <?= good?
> 
> On Fri, Jun 11, 2010 at 11:16 AM, Ashley Sheridan
> <a...@ashleysheridan.co.uk>wrote:
> 
> > For <?= to work, the short_tags setting needs to be turned 
> on I believe,
> > which can cause issues when outputting the XML declaration 
> line unless
> > it's broken into two parts, which is messier than '<?php echo' IMHO.
> >
> 
> Can you give an example of how this breaks? I don't see any 
> problems with
> 
>     <?= '<?xml blah blah ?>' ?>
> 
> unless you are trying to validate your PHP script as XML. 
> Given that PHP is
> *not* XML I don't know why you'd want to do that. But I've seen this
> argument a few times while looking into this issue so maybe 
> I'm just not
> seeing the big picture.

...and even *IF* it did break for that ONE instance, then simply do as I do
in my xml_header.inc.php file:

header( "Content-type: text/xml" );
print "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";

Problem solved.

EVERY other tag in an XML document is just straight up "html" like:

<foo>bar</foo>

There are no other <?xml tags or anything to worry about.

Again the whole XML argument seems to be exaggerated.


--- End Message ---
--- Begin Message ---
At 1:43 PM -0700 6/11/10, Daevid Vincent wrote:
 > -----Original Message-----
 > From: tedd [mailto:tedd.sperl...@gmail.com]
 > In fact, my practice is to not only use <?php echo, but to enclose
 the echo argument with a (), like:

 > <?php echo("The answer is $answer");?>

 I am sure there will be some that think that my practice is an
 overkill, or not "good practice", but it's a good thing that we all
 have a choice. Make your choice to best serve how you want your code
 to look.

As per http://us3.php.net/echo

echo() is not actually a function (it is a language construct), so you are
not required to use parentheses with it. echo() (unlike some other language
constructs) does not behave like a function, so it cannot always be used in
the context of a function. Additionally, if you want to pass more than one
parameter to echo(), the parameters must not be enclosed within
parentheses.

So you might want to reconsider your coding practice/style here and use the
construct as designed or you might end up with a far worse scenario than
short-tags could ever provide. Something more along the Python "print"
debacle.

Also, for the love of God, please don't embed a variable into a literal
string and use preprocessing.

Do it like so:

<?php echo 'The answer is '.$answer; ?>

Daevid:

I'm aware that echo is a language construct and does not require the (). However, please note the reference you provided, namely:

http://us3.php.net/echo

They use "echo()" to describe the construct -- so, if they can use it, then I figure I'm in good company.

I also practice using () because it is easier for *me* to read, understand, and document my work. You are free to do as you want.

As for the Python "print" problem, I don't do Python -- so, it can win the lottery, or die, I don't care.

As for "don't embed a variable into a literal string and use preprocessing", as I said above, I often do this:

<?php echo("The answer is $answer");?>

and find no problems whatsoever in doing so.

However, I wouldn't do this:

<?php echo 'The answer is '.$answer; ?>

OR, I would place a space before/after the . (i.e., 'The answer is ' . $answer). However, I don't like doing that because I also program in other languages, which use the dot operator differently.

My experience has shown me that most, if not all, languages are merging -- as such, I think the dot operator is more established as something other than just an operation to combine strings.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 2:19 PM -0700 6/11/10, Daevid Vincent wrote:
EVERY other tag in an XML document is just straight up "html" :

Just curious -- like html tags:

<hr>
<br>

Or do you have to change them to:

<hr />
<br />

How does XML handle those tags?

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On 6/11/2010 11:40 AM, Daevid Vincent wrote:

I use short tags and I output XML all the time.

I think there's a difference to note here. You're outputting XML from PHP, versus files having XML tags in the files ... I ran into a problem with short tags not too long ago when a client transferred their website to us. They had every single file starting with:

<?xml version="1.0" encoding="UTF-8"?>

When you have short_tags enabled, this causes problems. And because we have other clients who have applications written using short_tags, I had to redo all of those XML tags and make them:

<<??>?xml version="1.0" encoding="UTF-8"?>

This is why personally I refuse to use short tags - I'd rather type the whole thing out and not run into trouble later if for some reason I have to move hosts. None of my new servers have short_tags turned on. And anyone who asks is being told the same thing: type it out.
--- End Message ---
--- Begin Message ---
On Fri, Jun 11, 2010 at 2:51 PM, Ashley M. Kirchner <ash...@pcraft.com>wrote:

> They had every single file starting with:
>
> <?xml version="1.0" encoding="UTF-8"?>
>

*PHP* files? I would have flagged that as the problem rather than disabling
short tags.

David

--- End Message ---
--- Begin Message ---
On 6/11/2010 4:07 PM, David Harkness wrote:
*PHP* files? I would have flagged that as the problem rather than disabling
short tags.

Yeah, whoever created their site originally mixed XML/HTML/PHP all in the same file (all the files were .html but contained xml and php snippets) so I had to change their specific virtual host and then each individual file ...


--- End Message ---
--- Begin Message ---
On 6/12/2010 12:34 AM, tedd wrote:
At 2:19 PM -0700 6/11/10, Daevid Vincent wrote:
EVERY other tag in an XML document is just straight up "html" :

Just curious -- like html tags:

<hr>
<br>

Or do you have to change them to:

<hr />
<br />

How does XML handle those tags?

Cheers,

tedd


If they have no content, you should use <hr /> tags, otherwise use the full open and close tags around the content. <title>CONTENT</title>

--
Kind regards,
Ahmed Mohsen.

--- End Message ---
--- Begin Message ---
On 6/11/2010 11:43 PM, Daevid Vincent wrote:
-----Original Message-----
From: tedd [mailto:tedd.sperl...@gmail.com]

I believe, just because it can be done doesn't mean that it
should be done.

My practice is *never* to use<?=

In fact, my practice is to not only use<?php echo, but to enclose
the echo argument with a (), like:

<?php echo("The answer is $answer");?>

I am sure there will be some that think that my practice is an
overkill, or not "good practice", but it's a good thing that we all
have a choice. Make your choice to best serve how you want your code
to look.

As per http://us3.php.net/echo

echo() is not actually a function (it is a language construct), so you are
not required to use parentheses with it. echo() (unlike some other language
constructs) does not behave like a function, so it cannot always be used in
the context of a function. Additionally, if you want to pass more than one
parameter to echo(), the parameters must not be enclosed within
parentheses.

So you might want to reconsider your coding practice/style here and use the
construct as designed or you might end up with a far worse scenario than
short-tags could ever provide. Something more along the Python "print"
debacle.

Also, for the love of God, please don't embed a variable into a literal
string and use preprocessing.

Do it like so:

<?php echo 'The answer is '.$answer; ?>


Hey Daevid, does this form <?php echo 'The answer is '.$answer; ?> improve anything in processing time or it's just for the sake of readability?

--
Kind regards,
Ahmed Mohsen.

--- End Message ---
--- Begin Message ---
 

> -----Original Message-----
> From: Ahmed Mohsen [mailto:mre...@gmail.com] 
> Sent: Friday, June 11, 2010 4:25 PM
> To: php-gene...@lists.php.net
> Subject: Re: [PHP] is <?= good?
> 
> On 6/11/2010 11:43 PM, Daevid Vincent wrote:
> >> -----Original Message-----
> >> From: tedd [mailto:tedd.sperl...@gmail.com]
> >>
> >> I believe, just because it can be done doesn't mean that it
> >> should be done.
> >>
> >> My practice is *never* to use<?=
> >>
> >> In fact, my practice is to not only use<?php echo, but to enclose
> >> the echo argument with a (), like:
> >>
> >> <?php echo("The answer is $answer");?>
> >>
> >> I am sure there will be some that think that my practice is an
> >> overkill, or not "good practice", but it's a good thing that we all
> >> have a choice. Make your choice to best serve how you want 
> your code
> >> to look.
> >
> > As per http://us3.php.net/echo
> >
> > echo() is not actually a function (it is a language 
> construct), so you are
> > not required to use parentheses with it. echo() (unlike 
> some other language
> > constructs) does not behave like a function, so it cannot 
> always be used in
> > the context of a function. Additionally, if you want to 
> pass more than one
> > parameter to echo(), the parameters must not be enclosed within
> > parentheses.
> >
> > So you might want to reconsider your coding practice/style 
> here and use the
> > construct as designed or you might end up with a far worse 
> scenario than
> > short-tags could ever provide. Something more along the 
> Python "print"
> > debacle.
> >
> > Also, for the love of God, please don't embed a variable 
> into a literal
> > string and use preprocessing.
> >
> > Do it like so:
> >
> > <?php echo 'The answer is '.$answer; ?>
> >
> 
> Hey Daevid, does this form <?php echo 'The answer is '.$answer; ?> 
> improve anything in processing time or it's just for the sake of 
> readability?

Technically it does have a microscopic speed increase, but unless you're
pumping out hundreds or thousands of lines (like in a loop) you most likely
won't notice it. In my code, I always try to use the proper quote marks
because I *am* dealing with huge tables of data. I've said this a hundred
times before, if you can shave off 0.001 from each row, then after 1,000
rows, you've shaved 1 second off the page time. That seems small, but that
shit adds up. Caching will help, as the page is already parsed once, so PHP
doesn't have to do the work again in many cases. To me, it's a good habbit
and costs you nothing to do.

The difference is that with " the PHP engine has to pre-process the string
and look to see if there's anything interesting it needs to do -- such as
replace any $var with their equivalents or \n or whatever else. A ' means
to use it as is, so PHP just spits it back out.

http://php.net/manual/en/language.types.string.php

http://stackoverflow.com/questions/482202/is-there-a-performance-benefit-si
ngle-quote-vs-double-quote-in-php

http://stackoverflow.com/questions/13620/





--- End Message ---
--- Begin Message ---
On 12/06/2010, at 8:43 AM, Daevid Vincent wrote:

>> -----Original Message-----
>> From: tedd [mailto:tedd.sperl...@gmail.com] 
>> 
>> I believe, just because it can be done doesn't mean that it 
>> should be done.
>> 
>> My practice is *never* to use <?=
>> 
>> In fact, my practice is to not only use <?php echo, but to enclose 
>> the echo argument with a (), like:
>> 
>> <?php echo("The answer is $answer");?>
>> 
>> I am sure there will be some that think that my practice is an 
>> overkill, or not "good practice", but it's a good thing that we all 
>> have a choice. Make your choice to best serve how you want your code 
>> to look.
> 
> As per http://us3.php.net/echo
> 
> echo() is not actually a function (it is a language construct), so you are
> not required to use parentheses with it. echo() (unlike some other language
> constructs) does not behave like a function, so it cannot always be used in
> the context of a function. Additionally, if you want to pass more than one
> parameter to echo(), the parameters must not be enclosed within
> parentheses. 
> 
> So you might want to reconsider your coding practice/style here and use the
> construct as designed or you might end up with a far worse scenario than
> short-tags could ever provide. Something more along the Python "print"
> debacle.
> 
> Also, for the love of God, please don't embed a variable into a literal
> string and use preprocessing.
> 
> Do it like so:
> 
> <?php echo 'The answer is '.$answer; ?>

If you're doing it like that, you may as well use:

<?php echo 'The answer is', $answer; ?>

and leverage sending echo multiple parameters rather than using string 
concatenation.

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





--- End Message ---
--- Begin Message ---
Simon J Welsh wrote:
On 12/06/2010, at 8:43 AM, Daevid Vincent wrote:
Also, for the love of God, please don't embed a variable into a literal
string and use preprocessing.

Do it like so:

<?php echo 'The answer is '.$answer; ?>

If you're doing it like that, you may as well use:

<?php echo 'The answer is', $answer; ?>

<?php echo 'The answer is ', $answer; ?>

Fixed that for you :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
I'm trying to clean up some code and have been looking at error_log output
and they all look like this:

[11-Jun-2010 23:04:54] <font color='red'><b>In
/var/www/my_notifications.php, line 40:  WARNING</b>
Invalid argument supplied for foreach()
</font>

I can't figure out:

        [a] why the logs are in HTML format to begin with? Seems useless.
        [b] how do I turn it off and just be plain text (i.e. striptags()
)?
        [c] where is this <font color='red'> coming from?

I've looked in /etc/php5/apache2/ and grepped through, but don't see 'red'
anywhere.

I do see this, but it has no effect, as you can see by me 'disabling' it.

 388 ; String to output before an error message.
 389 ;error_prepend_string = "<font color=ff0000>"
 390 error_prepend_string = ""
 391
 392 ; String to output after an error message.
 393 ;error_append_string = "</font>"
 394 error_append_string = ""



--- End Message ---
--- Begin Message ---
On 12 June 2010 01:17, Daevid Vincent <dae...@daevid.com> wrote:
> I'm trying to clean up some code and have been looking at error_log output
> and they all look like this:
>
> [11-Jun-2010 23:04:54] <font color='red'><b>In
> /var/www/my_notifications.php, line 40:  WARNING</b>
> Invalid argument supplied for foreach()
> </font>
>
> I can't figure out:
>
>        [a] why the logs are in HTML format to begin with? Seems useless.
>        [b] how do I turn it off and just be plain text (i.e. striptags()
> )?
>        [c] where is this <font color='red'> coming from?
>
> I've looked in /etc/php5/apache2/ and grepped through, but don't see 'red'
> anywhere.
>
> I do see this, but it has no effect, as you can see by me 'disabling' it.
>
>  388 ; String to output before an error message.
>  389 ;error_prepend_string = "<font color=ff0000>"
>  390 error_prepend_string = ""
>  391
>  392 ; String to output after an error message.
>  393 ;error_append_string = "</font>"
>  394 error_append_string = ""
>

Did you check the html_errors directive?

Regards
Peter


-- 
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

--- End Message ---

Reply via email to