php-general Digest 26 Mar 2012 06:39:23 -0000 Issue 7745

2012-03-26 Thread php-general-digest-help

php-general Digest 26 Mar 2012 06:39:23 - Issue 7745

Topics (messages 317260 through 317262):

Re: foreach weirdness
317260 by: Matijn Woudt
317261 by: Simon Schick
317262 by: Arno Kuhl

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


--
---BeginMessage---
On Sun, Mar 25, 2012 at 4:11 PM, Arno Kuhl a...@dotcontent.net wrote:
 From: Simon Schick [mailto:simonsimc...@googlemail.com]
 Sent: 24 March 2012 12:30 AM
 To: Robert Cummings
 Cc: a...@dotcontent.net; php-gene...@lists.php.net
 Subject: Re: [PHP] foreach weirdness

 2012/3/23 Robert Cummings rob...@interjinn.com

 On 12-03-23 11:16 AM, Arno Kuhl wrote:


 it still does not produce the correct result:
 0 1 3 6 10 15 21
 0 1 3 6 10 15 15


 This looks like a bug... the last row should be the same. What version
 of PHP are you using? Have you checked the online bug reports?



 Hi, Robert

 Does not seem like a bug to me ...
 http://schlueters.de/blog/archives/141-References-and-foreach.html

 What you should do to get the expected result:
 Unset the variable after you don't need this reference any longer.

 Bye
 Simon

 --

 Hi Simon, unsetting the $value does fix the problem, but I found that any 
 time you assign $value by reference in a foreach loop you have to do an unset 
 to avoid corrupting the array unless you continue to assign $value by 
 reference (as illustrated in the article you linked).

 So doing something as simple as:
 $array = array(0, 1, 2, 3, 4, 5, 6);
 foreach ($array as $key=$value) {
        echo Key: $key; Value: $valuebr /\n;
 }

 and then follow with (from the php manual):
 foreach ($array as $key=$value) {
        echo Key: $key; Value: $valuebr /\n;
 }

 will not only give the wrong result, it will corrupt the array for *any* 
 further use of that array. I still think it’s a bug according to the 
 definition of foreach in the php manual. Maybe php needs to do an implicit 
 unset at the closing brace of the foreach where was an assign $value by 
 reference, to remove the reference to the last element (or whatever element 
 it was pointing to if there was a break) so that it doesn't corrupt the 
 array, because any assign to $value after the foreach loop is completed will 
 corrupt the array (confirmed by testing). The average user (like me) wouldn't 
 think twice about reusing $value after ending the foreach loop, not realising 
 that without an unset the array will be corrupted.

 BTW thanks for that reference, it was quite an eye-opener on the pitfalls of 
 using assign by reference, not only in the foreach loop.

 Cheers
 Arno

Note that somewhat similar error was discussed on this list a few
months ago[1]. You could probably have solved it yourself if you
searched the mailing list archives.

- Matijn

[1] http://www.mail-archive.com/php-general@lists.php.net/msg269552.html
---End Message---
---BeginMessage---
2012/3/25 Arno Kuhl a...@dotcontent.net:

 will not only give the wrong result, it will corrupt the array for *any* 
 further use of that array. I still think it’s a bug according to the 
 definition of foreach in the php manual. Maybe php needs to do an implicit 
 unset at the closing brace of the foreach where was an assign $value by 
 reference, to remove the reference to the last element (or whatever element 
 it was pointing to if there was a break) so that it doesn't corrupt the 
 array, because any assign to $value after the foreach loop is completed will 
 corrupt the array (confirmed by testing). The average user (like me) wouldn't 
 think twice about reusing $value after ending the foreach loop, not realising 
 that without an unset the array will be corrupted.


Hi, Arno

Requesting that will at least require a major-release (f.e. PHP 6.0)
... but I would rather request to add a notice or warning to the
documentation of references to remind stuff like that.
http://www.php.net/manual/en/language.references.php
I think this is stuff more people will stumble over ...

Bye
Simon
---End Message---
---BeginMessage---
Requesting that will at least require a major-release (f.e. PHP 6.0) ... but I 
would rather request to add a notice or warning to the documentation of 
references to remind stuff like that.
http://www.php.net/manual/en/language.references.php
I think this is stuff more people will stumble over ...

Bye
Simon
--

I agree it would be wrong to change php's handling of call by reference in 
foreach loops because there may be a need to access that reference after 
completing the loop. I was going to suggest there should be a warning in the 
manual to unset the reference after the foreach loop is completed, but I see 
the current online manual has that warning prominently displayed on the foreach 

php-general Digest 26 Mar 2012 19:16:14 -0000 Issue 7746

2012-03-26 Thread php-general-digest-help

php-general Digest 26 Mar 2012 19:16:14 - Issue 7746

Topics (messages 317263 through 317277):

Re: foreach weirdness
317263 by: Arno Kuhl

including PHP code from another server..
317264 by: rene7705
317265 by: Stuart Dallas
317266 by: Simon Schick
317267 by: Stuart Dallas
317268 by: Stuart Dallas
317269 by: Curtis Maurand
317270 by: rene7705
317272 by: Lester Caine
317273 by: Alex Pojarsky
317277 by: Stuart Dallas

CURL -d
317271 by: QI.VOLMAR QI

Re: Thinking out loud - a continuation...
317274 by: Jay Blanchard
317275 by: Stuart Dallas
317276 by: Jay Blanchard

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


--
---BeginMessage---
Note that somewhat similar error was discussed on this list a few months 
ago[1]. You could probably have solved it yourself if you searched the mailing 
list archives.

- Matijn

[1] http://www.mail-archive.com/php-general@lists.php.net/msg269552.html
---

Thanks Matijn, I missed that discussion, not following the list that actively. 
I'll try search next time before raising an issue.

Cheers
Arno

---End Message---
---BeginMessage---
Hi.

My last thread got derailed into a javascript and even photoshop
discussion, and while I can't blame myself for that really, this time I
would like to bring a pure PHP issue to your scrutiny.

I run several sites now, on the same shared hoster, but with such a setup
that I cannot let PHP require() or include() code from a central place
located on another domain name on the same shared hosting account, not the
normal way at least.
$_SERVER['DOCUMENT_ROOT'] is a completely different path for each of the
domains on the same hosting account, and obviously you can't access one
domain's directory from another domain.

Hoster support's reply is A) I dont know code, B) You can't include code
from one domain on another and C) use multiple copies, 1 for each domain

But that directory (my opensourced /code in the zip on
http://mediabeez.wsbtw), takes a while to update to my hoster, many
files.
Plus, as I add more domains that use the same code base, my overhead and
waiting time increases lineary at a steep incline.

So.. Since all of this code is my own, and tested and trusted, I can just
eval(file_get_contents('
http://sitewithwantedcode.com/code/get_php.php?file=/code/sitewide_rv/autorun.php'))
hehe
And get_php.php takes care of the nested includes by massaging what it
retrieves. Or so is my thinking.

The problem I'm facing, and for which I'm asking your most scrutinous
feedback, is:
How would you transform _nested_ require(_once) and include(_once)? I
haven't figured out yet how to transform a relative path include/require.
What about for instance a require_once($fileIwantNow)?
I do both in my /code tree atm.

For my own purposes, I could massage my own PHP in /code/libraries_rv and
/code/sitewide_rv manually, but I'd also like to be able to include a
single copy of the 3rd party free libs that I use in
/code/libraries(/adodb-5.10 for instance). And god knows how they might
include and require.

Plus, I'd like to turn this into another free how-to blog entry on
http://mediabeez.ws, plus accompanying code, so I think I might find some
free tips here again.

Greetings,
 from spring sun soaked amsterdam.nl,
 Rene
---End Message---
---BeginMessage---
REMOVE THAT SCRIPT FROM YOUR SERVER RIGHT NOW!

See follow-up email direct to you for the reason!

On 26 Mar 2012, at 14:53, rene7705 wrote:

 Hi.
 
 My last thread got derailed into a javascript and even photoshop
 discussion, and while I can't blame myself for that really, this time I
 would like to bring a pure PHP issue to your scrutiny.
 
 I run several sites now, on the same shared hoster, but with such a setup
 that I cannot let PHP require() or include() code from a central place
 located on another domain name on the same shared hosting account, not the
 normal way at least.
 $_SERVER['DOCUMENT_ROOT'] is a completely different path for each of the
 domains on the same hosting account, and obviously you can't access one
 domain's directory from another domain.
 
 Hoster support's reply is A) I dont know code, B) You can't include code
 from one domain on another and C) use multiple copies, 1 for each domain
 
 But that directory (my opensourced /code in the zip on
 http://mediabeez.wsbtw), takes a while to update to my hoster, many
 files.
 Plus, as I add more domains that use the same code base, my overhead and
 waiting time increases lineary at a steep incline.
 
 So.. Since all of this code is my own, and tested and trusted, I can just
 eval(file_get_contents('