[PHP] PHP -r, -a and .php return different results based upon or ' marks !? [BUG]

2010-06-10 Thread Daevid Vincent
Chew on this...

develo...@mypse:~$ cat ./md5test.php
#!/usr/bin/php
?php
$password = '12345678';
echo md5(strtoupper($password));
echo \n;
echo md5(strtoupper('12345678'));
echo \n;

$password = '$12345678';
echo md5(strtoupper($password));
echo \n;
echo md5(strtoupper('$12345678'));
echo \n;
?

develo...@mypse:~$ ./md5test.php
25d55ad283aa400af464c76d713c07ad
25d55ad283aa400af464c76d713c07ad
2d05c0e3d6d22343123eae7f5678e34c
2d05c0e3d6d22343123eae7f5678e34c

develo...@mypse:~$ php -r echo md5(strtoupper('12345678'));
25d55ad283aa400af464c76d713c07ad

develo...@mypse:~$ php -a
Interactive shell
php  echo md5(strtoupper('$12345678'));
2d05c0e3d6d22343123eae7f5678e34c

develo...@mypse:~$ php -r echo md5(strtoupper('$12345678'));
b3275960d68fda9d831facc0426c3bbc

Why is the -r command line version different?

man php:

   Using parameter -r you can directly execute  PHP  code  simply  as
you
   would do inside a .php file when using the eval() function.

develo...@mypse:~$ php -v
PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
22:01:14)
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

Then I tried it again on two different servers with the same result:

PHP 5.2.6-2ubuntu4.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
22:03:33)
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)

Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

So now it get's more interesting...

A co-worker suggested to reverse the quotes:

develo...@mypse:~$ php -r 'echo md5(strtoupper($12345678));'
2d05c0e3d6d22343123eae7f5678e34c

Note the use of the single and double quotes are reversed. This gives me
the RIGHT checksum.

To me this version is syntactically wrong because the  would indicate in
normal PHP to pre-parse the literal $12345678 and treat $1 as some kind of
variable or something. Whereas a ' says use the literal AS IS.

Not to mention that it is completely confusing that -r gives different
results than -a and using it in a .php file all together. 

IF quotes are a factor (as they seem to be), then the -r PHP
behind-the-scenes code should flip them around or something so the
developer doesn't have to be concerned with this edge case nonsense. 

Sanity would dictate that all ways of executing the SAME PHP code would
give the SAME results.

*sigh*


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



Re: [PHP] PHP -r, -a and .php return different results based upon or ' marks !? [BUG]

2010-06-10 Thread Simon J Welsh

On 11/06/2010, at 12:49 PM, Daevid Vincent wrote:

 Chew on this...
 
 develo...@mypse:~$ cat ./md5test.php
 #!/usr/bin/php
 ?php
 $password = '12345678';
 echo md5(strtoupper($password));
 echo \n;
 echo md5(strtoupper('12345678'));
 echo \n;
 
 $password = '$12345678';
 echo md5(strtoupper($password));
 echo \n;
 echo md5(strtoupper('$12345678'));
 echo \n;
 ?
 
 develo...@mypse:~$ ./md5test.php
 25d55ad283aa400af464c76d713c07ad
 25d55ad283aa400af464c76d713c07ad
 2d05c0e3d6d22343123eae7f5678e34c
 2d05c0e3d6d22343123eae7f5678e34c
 
 develo...@mypse:~$ php -r echo md5(strtoupper('12345678'));
 25d55ad283aa400af464c76d713c07ad
 
 develo...@mypse:~$ php -a
 Interactive shell
 php  echo md5(strtoupper('$12345678'));
 2d05c0e3d6d22343123eae7f5678e34c
 
 develo...@mypse:~$ php -r echo md5(strtoupper('$12345678'));
 b3275960d68fda9d831facc0426c3bbc
 
 Why is the -r command line version different?
 
 man php:
 
   Using parameter -r you can directly execute  PHP  code  simply  as
 you
   would do inside a .php file when using the eval() function.
 
 develo...@mypse:~$ php -v
 PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
 22:01:14)
 Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
 
 Then I tried it again on two different servers with the same result:
 
 PHP 5.2.6-2ubuntu4.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
 22:03:33)
 Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
 
 PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)
 
 Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
 
 So now it get's more interesting...
 
 A co-worker suggested to reverse the quotes:
 
 develo...@mypse:~$ php -r 'echo md5(strtoupper($12345678));'
 2d05c0e3d6d22343123eae7f5678e34c
 
 Note the use of the single and double quotes are reversed. This gives me
 the RIGHT checksum.
 
 To me this version is syntactically wrong because the  would indicate in
 normal PHP to pre-parse the literal $12345678 and treat $1 as some kind of
 variable or something. Whereas a ' says use the literal AS IS.
 
 Not to mention that it is completely confusing that -r gives different
 results than -a and using it in a .php file all together. 
 
 IF quotes are a factor (as they seem to be), then the -r PHP
 behind-the-scenes code should flip them around or something so the
 developer doesn't have to be concerned with this edge case nonsense. 
 
 Sanity would dictate that all ways of executing the SAME PHP code would
 give the SAME results.
 
 *sigh*

It's your shell doing what it's supposed to, by replacing $12345678, when the 
entire string's in double quotes, with the contents of the shell variable 
12345678 (most likely nothing), so all that PHP sees is: echo 
md5(strtoupper(''));
---
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





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



Re: [PHP] PHP -r, -a and .php return different results based upon or ' marks !? [BUG]

2010-06-10 Thread Ashley Sheridan
On Thu, 2010-06-10 at 17:49 -0700, Daevid Vincent wrote:

 Chew on this...
 
 develo...@mypse:~$ cat ./md5test.php
 #!/usr/bin/php
 ?php
 $password = '12345678';
 echo md5(strtoupper($password));
 echo \n;
 echo md5(strtoupper('12345678'));
 echo \n;
 
 $password = '$12345678';
 echo md5(strtoupper($password));
 echo \n;
 echo md5(strtoupper('$12345678'));
 echo \n;
 ?
 
 develo...@mypse:~$ ./md5test.php
 25d55ad283aa400af464c76d713c07ad
 25d55ad283aa400af464c76d713c07ad
 2d05c0e3d6d22343123eae7f5678e34c
 2d05c0e3d6d22343123eae7f5678e34c
 
 develo...@mypse:~$ php -r echo md5(strtoupper('12345678'));
 25d55ad283aa400af464c76d713c07ad
 
 develo...@mypse:~$ php -a
 Interactive shell
 php  echo md5(strtoupper('$12345678'));
 2d05c0e3d6d22343123eae7f5678e34c
 
 develo...@mypse:~$ php -r echo md5(strtoupper('$12345678'));
 b3275960d68fda9d831facc0426c3bbc
 
 Why is the -r command line version different?
 
 man php:
 
Using parameter -r you can directly execute  PHP  code  simply  as
 you
would do inside a .php file when using the eval() function.
 
 develo...@mypse:~$ php -v
 PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
 22:01:14)
 Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
 
 Then I tried it again on two different servers with the same result:
 
 PHP 5.2.6-2ubuntu4.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan  6 2010
 22:03:33)
 Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
 
 PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)
 
 Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
 
 So now it get's more interesting...
 
 A co-worker suggested to reverse the quotes:
 
 develo...@mypse:~$ php -r 'echo md5(strtoupper($12345678));'
 2d05c0e3d6d22343123eae7f5678e34c
 
 Note the use of the single and double quotes are reversed. This gives me
 the RIGHT checksum.
 
 To me this version is syntactically wrong because the  would indicate in
 normal PHP to pre-parse the literal $12345678 and treat $1 as some kind of
 variable or something. Whereas a ' says use the literal AS IS.
 
 Not to mention that it is completely confusing that -r gives different
 results than -a and using it in a .php file all together. 
 
 IF quotes are a factor (as they seem to be), then the -r PHP
 behind-the-scenes code should flip them around or something so the
 developer doesn't have to be concerned with this edge case nonsense. 
 
 Sanity would dictate that all ways of executing the SAME PHP code would
 give the SAME results.
 
 *sigh*
 
 


I believe that when you're running the PHP with the -r, the quotation
marks are treated as Bash (or whichever shell you're using) quotes, and
so the variable is possibly being parsed as an empty string value, which
is why reversing the quotes is having the right effect.

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




Re: [PHP] Return XML attribute in DOM

2009-09-08 Thread Peter Ford
Matthew Croud wrote:
 Doesn't the DOM have the getAttribute() method?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 It's not in my reference, though I see it in the PHP manual now.
 This is what I have:
 
 _
 
 $dom = new DomDocument();
 $dom - load(items.xml);
 
 $topics = $dom - getElementsByTagName(item);
 
 echo(ul);
 foreach ($topics as $node )
 {
 echo(li. $node - hasAttributes() ./li);   
 }
 echo(/ul);
 
 __
 
 I'm replacing hasAttributes() with getAttribute() but its throwing me an
 error, I'm probably using it incorrectly.
 I think I'm drowning in the deep end =/
 Could you advise Gamesmaster ?


It's a method on DomElement:
http://uk3.php.net/manual/en/function.domelement-get-attribute.php

and you need to tell it which attribute to get... :)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Return XML attribute in DOM

2009-09-08 Thread Matthew Croud


Cheers Guys,
Your the greatest !



On 8 Sep 2009, at 09:08, Peter Ford wrote:


Matthew Croud wrote:

Doesn't the DOM have the getAttribute() method?


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


It's not in my reference, though I see it in the PHP manual now.
This is what I have:

_

$dom = new DomDocument();
$dom - load(items.xml);

$topics = $dom - getElementsByTagName(item);

echo(ul);
foreach ($topics as $node )
{
   echo(li. $node - hasAttributes() ./li);
}
echo(/ul);

__

I'm replacing hasAttributes() with getAttribute() but its throwing  
me an

error, I'm probably using it incorrectly.
I think I'm drowning in the deep end =/
Could you advise Gamesmaster ?



It's a method on DomElement:
http://uk3.php.net/manual/en/function.domelement-get-attribute.php

and you need to tell it which attribute to get... :)

--
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com







[PHP] Return XML attribute in DOM

2009-09-07 Thread Matthew Croud



I'm at my wits end here, so close to the finishing line!

Is there a method to return an attribute value of an XML node using  
DOM, I can check to see if an attribute exists using hasAttributes()

But I can't retrieve the value.

I'm so desperate i've started to eat dirt.

Many thanks,
Matt

Re: [PHP] Return XML attribute in DOM

2009-09-07 Thread Ashley Sheridan
On Mon, 2009-09-07 at 16:37 +0100, Matthew Croud wrote:
 
 I'm at my wits end here, so close to the finishing line!
 
 Is there a method to return an attribute value of an XML node using  
 DOM, I can check to see if an attribute exists using hasAttributes()
 But I can't retrieve the value.
 
 I'm so desperate i've started to eat dirt.
 
 Many thanks,
 Matt

Doesn't the DOM have the getAttribute() method?

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




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



Re: [PHP] Return XML attribute in DOM

2009-09-07 Thread Matthew Croud

Doesn't the DOM have the getAttribute() method?


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


It's not in my reference, though I see it in the PHP manual now.
This is what I have:

_

$dom = new DomDocument();
$dom - load(items.xml);

$topics = $dom - getElementsByTagName(item);

echo(ul);
foreach ($topics as $node )
{
echo(li. $node - hasAttributes() ./li); 
}
echo(/ul);

__

I'm replacing hasAttributes() with getAttribute() but its throwing me  
an error, I'm probably using it incorrectly.

I think I'm drowning in the deep end =/
Could you advise Gamesmaster ?

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



[PHP] return language of a word

2008-09-29 Thread shahrzad khorrami
hi all,

is there any function to return us the lanuage of a word in the sentence?

for example : My name is شهرزاد .

when it sees شهرزاد notice that is a persian language.


Thanks


Re: [PHP] return language of a word

2008-09-29 Thread Robin Vickery
2008/9/29 shahrzad khorrami [EMAIL PROTECTED]:
 hi all,

 is there any function to return us the lanuage of a word in the sentence?

 for example : My name is شهرزاد .

 when it sees شهرزاد notice that is a persian language.

As others have said, you can check what unicode block the characters are from.

For segments of text that are a little longer (one or two sentences),
you can use n-gram based language identification, which can sometimes
be spookily accurate. If you want to give that a go, there's a Pear
package called Text::LanguageDetect which will do that
[http://pear.php.net/package/Text_LanguageDetect]. It doesn't have
trigrams for Persian in the lang.dat, but I don't imagine it would be
too hard to add them, if that's what you need.

-robin


Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Jim Lucas

Bojan Tesanovic wrote:


On Apr 12, 2008, at 12:33 AM, Daniel Kolbo wrote:


Hello,

I want to return an array from function and reference an index all in 
one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.   



function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being converted 
to a string.  $yo === NULL...not what i want.


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.

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





This is not possible in PHP, though you can have a Array wrapper class

function returnarray() {
return new ArrayObject( array('lose' = array(5,6), 'win' = 
array(9,8)) );

}
var_dump (returnarray()-offsetGet('lose'));


or even better make you own wrapper class with __set() and __get()  
methods so you can have


var_dump (returnarray()-lose);

of course only in PHP5


Well, not quite so fast saying this is only possible in PHP5

You could do something like this.

?php

function returnHash() {
  return (object) array('lose' = array(5,6), 'win' = array(9,8));
}

print_r(returnHash()-lose);

?

Basically, this converts your newly built array into an object, using 
the stdClass object.


Then reference the index via an object variable name instead of an array 
style access method.







Bojan Tesanovic
http://www.carster.us/









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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Stut

On 12 Apr 2008, at 00:31, Daniel Kolbo wrote:

Philip Thompson wrote:

On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote:
I want to return an array from function and reference an index all  
in one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being  
converted to a string.  $yo === NULL...not what i want.


function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.


The PHP parser does not support this, but you may see it in a future  
version - it's a commonly requested feature.


There are various ways to code around this limitation as other posters  
have stated but to me they all add far too much processing to make it  
worth saving a line of code and a temporary variable.


-Stut

--
http://stut.net/

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Daniel Kolbo



Jim Lucas wrote:

Bojan Tesanovic wrote:


On Apr 12, 2008, at 12:33 AM, Daniel Kolbo wrote:


Hello,

I want to return an array from function and reference an index all in 
one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.  


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being converted 
to a string.  $yo === NULL...not what i want.


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.

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





This is not possible in PHP, though you can have a Array wrapper class

function returnarray() {
return new ArrayObject( array('lose' = array(5,6), 'win' = 
array(9,8)) );

}
var_dump (returnarray()-offsetGet('lose'));


or even better make you own wrapper class with __set() and __get()  
methods so you can have


var_dump (returnarray()-lose);

of course only in PHP5


Well, not quite so fast saying this is only possible in PHP5

You could do something like this.

?php

function returnHash() {
  return (object) array('lose' = array(5,6), 'win' = array(9,8));
}

print_r(returnHash()-lose);

?

Basically, this converts your newly built array into an object, using 
the stdClass object.


Then reference the index via an object variable name instead of an array 
style access method.







Bojan Tesanovic
http://www.carster.us/











Thanks, I appreciate your comment Bojan
DanK

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Daniel Kolbo



Stut wrote:

On 12 Apr 2008, at 00:31, Daniel Kolbo wrote:

Philip Thompson wrote:

On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote:
I want to return an array from function and reference an index all 
in one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being converted 
to a string.  $yo === NULL...not what i want.


function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.


The PHP parser does not support this, but you may see it in a future 
version - it's a commonly requested feature.


There are various ways to code around this limitation as other posters 
have stated but to me they all add far too much processing to make it 
worth saving a line of code and a temporary variable.


-Stut



Thanks Stut.  By chance do you know of any proposed syntax for this 
feature?  Or, what syntax would seem logical to you?


DanK

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Stut

On 12 Apr 2008, at 15:18, Daniel Kolbo wrote:

Stut wrote:

On 12 Apr 2008, at 00:31, Daniel Kolbo wrote:

Philip Thompson wrote:

On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote:
I want to return an array from function and reference an index  
all in one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
  return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
  return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
  return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being  
converted to a string.  $yo === NULL...not what i want.


function returnarray() {
  return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
  return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.
The PHP parser does not support this, but you may see it in a  
future version - it's a commonly requested feature.
There are various ways to code around this limitation as other  
posters have stated but to me they all add far too much processing  
to make it worth saving a line of code and a temporary variable.

-Stut


Thanks Stut.  By chance do you know of any proposed syntax for this  
feature?  Or, what syntax would seem logical to you?


I'm sure I've seen it discussed on the internals list but I don't know  
if anything has been agreed. Your best bet is to search the archives  
for the internals list.


-Stut

--
http://stut.net/

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Nathan Nobbe
On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo [EMAIL PROTECTED] wrote:

search the archives ;)

http://www.mail-archive.com/php-general@lists.php.net/msg224626.html

-nathan


Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Casey
On Sat, Apr 12, 2008 at 9:12 AM, Nathan Nobbe [EMAIL PROTECTED] wrote:
 On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo [EMAIL PROTECTED] wrote:

  search the archives ;)

  http://www.mail-archive.com/php-general@lists.php.net/msg224626.html

  -nathan
?php
function ReturnArray() {
return array('a' = 'f', 'b' = 'g', 'c' = 'h', 'd' = 'i', 'e' = 'j');
}

echo ${!${!1}=ReturnArray()}['a']; // 'f'
?

:)
-- 
-Casey

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Nathan Nobbe
On Sat, Apr 12, 2008 at 12:18 PM, Casey [EMAIL PROTECTED] wrote:

 On Sat, Apr 12, 2008 at 9:12 AM, Nathan Nobbe [EMAIL PROTECTED]
 wrote:
  On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo [EMAIL PROTECTED] wrote:
 
   search the archives ;)
 
   http://www.mail-archive.com/php-general@lists.php.net/msg224626.html
 
   -nathan
 ?php
 function ReturnArray() {
return array('a' = 'f', 'b' = 'g', 'c' = 'h', 'd' = 'i', 'e' =
 'j');
 }

 echo ${!${!1}=ReturnArray()}['a']; // 'f'
 ?


ya; i never did sit down and try to figure out how that works; care to
explain ?

-nathan


Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Casey
On Sat, Apr 12, 2008 at 9:35 AM, Nathan Nobbe [EMAIL PROTECTED] wrote:

 On Sat, Apr 12, 2008 at 12:18 PM, Casey [EMAIL PROTECTED] wrote:


 
 
 
  On Sat, Apr 12, 2008 at 9:12 AM, Nathan Nobbe [EMAIL PROTECTED]
 wrote:
   On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo [EMAIL PROTECTED] wrote:
  
search the archives ;)
  
http://www.mail-archive.com/php-general@lists.php.net/msg224626.html
  
-nathan
  ?php
  function ReturnArray() {
 return array('a' = 'f', 'b' = 'g', 'c' = 'h', 'd' = 'i', 'e' =
 'j');
  }
 
  echo ${!${!1}=ReturnArray()}['a']; // 'f'
  ?

 ya; i never did sit down and try to figure out how that works; care to
 explain ?

 -nathan


?php
echo ${!${!1}=ReturnArray()}['a'];

${!${!1}=ReturnArray()}['a']
 !1 resolves to false.
${!${false}=ReturnArray()}['a']
 false resolves to... I don't know. Let's just say false resolves to a.
${!$a=ReturnArray()}['a']
 $a is now the array. The ! changes the returned array into the
boolean false (like: if (!$handle = fopen('x', 'r')) { echo
'connection failed' }.
${false}['a']
 I don't know what false resolves to, but we're using a.
$a['a']
?
-- 
-Casey

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Daniel Kolbo



Casey wrote:

On Sat, Apr 12, 2008 at 9:35 AM, Nathan Nobbe [EMAIL PROTECTED] wrote:

On Sat, Apr 12, 2008 at 12:18 PM, Casey [EMAIL PROTECTED] wrote:





On Sat, Apr 12, 2008 at 9:12 AM, Nathan Nobbe [EMAIL PROTECTED]

wrote:

On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo [EMAIL PROTECTED] wrote:

 search the archives ;)

 http://www.mail-archive.com/php-general@lists.php.net/msg224626.html

 -nathan

?php
function ReturnArray() {
   return array('a' = 'f', 'b' = 'g', 'c' = 'h', 'd' = 'i', 'e' =

'j');

}

echo ${!${!1}=ReturnArray()}['a']; // 'f'
?

ya; i never did sit down and try to figure out how that works; care to
explain ?

-nathan



?php
echo ${!${!1}=ReturnArray()}['a'];

${!${!1}=ReturnArray()}['a']
 !1 resolves to false.
${!${false}=ReturnArray()}['a']
 false resolves to... I don't know. Let's just say false resolves to a.
${!$a=ReturnArray()}['a']
 $a is now the array. The ! changes the returned array into the
boolean false (like: if (!$handle = fopen('x', 'r')) { echo
'connection failed' }.
${false}['a']
 I don't know what false resolves to, but we're using a.
$a['a']
?


Just awesome!  Thanks for the explanation Casey, and thanks for the 
archived link Nathan.  I knew I'd learn something by asking.


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



Re: [PHP] Return an Array and immediately reference an index

2008-04-12 Thread Bojan Tesanovic


On Apr 12, 2008, at 6:18 PM, Casey wrote:

On Sat, Apr 12, 2008 at 9:12 AM, Nathan Nobbe  
[EMAIL PROTECTED] wrote:
On Fri, Apr 11, 2008 at 6:33 PM, Daniel Kolbo [EMAIL PROTECTED]  
wrote:


 search the archives ;)

 http://www.mail-archive.com/php-general@lists.php.net/msg224626.html

 -nathan

?php
function ReturnArray() {
return array('a' = 'f', 'b' = 'g', 'c' = 'h', 'd' = 'i',  
'e' = 'j');

}

echo ${!${!1}=ReturnArray()}['a']; // 'f'
?

:)
--
-Casey

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





WOW!! PHP always surprises  me, this is the pros of PHP not being  
strict type language.


Igor Jocic
http://www.carster.us/






[PHP] Return an Array and immediately reference an index

2008-04-11 Thread Daniel Kolbo

Hello,

I want to return an array from function and reference an index all in 
one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.  


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being converted to 
a string.  $yo === NULL...not what i want.


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-11 Thread Philip Thompson

Top-posting side comment: It's not nice to hijack threads.

My comments are below...

On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote:

Hello,

I want to return an array from function and reference an index all  
in one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.  


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being converted  
to a string.  $yo === NULL...not what i want.


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.



Perhaps these pages may assist you:

http://php.net/manual/en/function.array.php
http://php.net/functions

For more immediate help, I think you want to do something along these  
lines:


?php
function returnArray ($index) {
$arr = array('lose'=array(5,6), 'win'=array(9,8));
return isset ($arr[$index]) ? $arr[$index] : 'Index not found';
}

$returnTheValueForThis = 'lose';
$result = returnArray ($returnTheValueForThis);
var_dump ($result);
?

This var_dump will return:

array(2) { [0]=  int(5) [1]=  int(6) }

Hope that helps. Do some more reading in the manual to help yourself  
out. ;)


~Philip

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-11 Thread Daniel Kolbo



Philip Thompson wrote:

Top-posting side comment: It's not nice to hijack threads.

My comments are below...

On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote:

Hello,

I want to return an array from function and reference an index all in 
one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.   



function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being converted 
to a string.  $yo === NULL...not what i want.


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.



Perhaps these pages may assist you:

http://php.net/manual/en/function.array.php
http://php.net/functions

For more immediate help, I think you want to do something along these 
lines:


?php
function returnArray ($index) {
$arr = array('lose'=array(5,6), 'win'=array(9,8));
return isset ($arr[$index]) ? $arr[$index] : 'Index not found';
}

$returnTheValueForThis = 'lose';
$result = returnArray ($returnTheValueForThis);
var_dump ($result);
?

This var_dump will return:

array(2) { [0]=  int(5) [1]=  int(6) }

Hope that helps. Do some more reading in the manual to help yourself 
out. ;)


~Philip



Just to be sure, where you saying I hijacked a thread?  If so, please 
educate me as to how i did this.  Now to the response.


Thanks for the response.

I am familiar with the construction and returning of the arrays and 
referencing an index of the array.  I understand your code.  However, 
this is not what I am trying to do.


I could simply do:

function returnarray() {
 return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray();
var_dump($yo['lose']);

To get my desired result.

I was just seeing if PHP had the capability to combine those last two 
lines into one.  I realize the function itself is rather trivial, but 
just wanted some function to return an array for the sake of demonstration.


Thanks,

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-11 Thread Philip Thompson

On Apr 11, 2008, at 6:31 PM, Daniel Kolbo wrote:


Philip Thompson wrote:

Top-posting side comment: It's not nice to hijack threads.
My comments are below...
On Apr 11, 2008, at 5:33 PM, Daniel Kolbo wrote:

Hello,

I want to return an array from function and reference an index all  
in one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being  
converted to a string.  $yo === NULL...not what i want.


function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
   return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.

Perhaps these pages may assist you:
http://php.net/manual/en/function.array.php
http://php.net/functions
For more immediate help, I think you want to do something along  
these lines:

?php
function returnArray ($index) {
   $arr = array('lose'=array(5,6), 'win'=array(9,8));
   return isset ($arr[$index]) ? $arr[$index] : 'Index not found';
}
$returnTheValueForThis = 'lose';
$result = returnArray ($returnTheValueForThis);
var_dump ($result);
?
This var_dump will return:
array(2) { [0]=  int(5) [1]=  int(6) }
Hope that helps. Do some more reading in the manual to help  
yourself out. ;)

~Philip


Just to be sure, where you saying I hijacked a thread?  If so,  
please educate me as to how i did this.  Now to the response.


If you are viewing a message (in this case, the thread entitled  
Quarters -- ERRORS --) and you hit Reply and change the message to  
whatever (in this case, Return an Array and immediately reference an  
index), it still shows up in the same thread as the Quarters one.  
This implies that your email has to do with the Quarters one... but it  
really doesn't. =D


So, in order to fix this, just hit New instead of Reply. =D No harm  
done, just good listserv netiquette for people reading their emails  
that shove the *same content* emails together. We're all here to  
learn, right.




Thanks for the response.

I am familiar with the construction and returning of the arrays and  
referencing an index of the array.  I understand your code.   
However, this is not what I am trying to do.


I could simply do:

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray();
var_dump($yo['lose']);

To get my desired result.

I was just seeing if PHP had the capability to combine those last  
two lines into one.  I realize the function itself is rather  
trivial, but just wanted some function to return an array for the  
sake of demonstration.


Thanks,


Oooh. I see what you're saying now. Sorry for the confusion. To my  
knowledge (which is limited ;), I don't think you can do that. This is  
somewhat similar to some desired functionality in PHP - I don't  
remember the name of it. For example,


?php
class f1() {
  function f2() {
echo Hello;
  }

  function f3() {
echo World!;
  }
}

new f1()-f2() . new f1()-f3();
?

Something like that. Basically, call a class/function and get the  
contents directly without instantiating it first. Maybe others have an  
opinion on this


~Philip

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



Re: [PHP] Return an Array and immediately reference an index

2008-04-11 Thread Bojan Tesanovic


On Apr 12, 2008, at 12:33 AM, Daniel Kolbo wrote:


Hello,

I want to return an array from function and reference an index all  
in one line.  Is this possible?


In the code below I want I want $yo to be the array(5,6).

Here is what I've tried,

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()['lose'];
var_dump($yo);

This yields a parse error.  


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = {returnarray()}['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}['lose'];
var_dump($yo);

This gives notices as the result of returnarray() is being  
converted to a string.  $yo === NULL...not what i want.


function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = returnarray()-['lose'];
var_dump($yo);

This yields a parse error.

function returnarray() {
return array('lose' = array(5,6), 'win' = array(9,8));
}

$yo = ${returnarray()}-['lose'];
var_dump($yo);

This yields a parse error.

Thanks for your help in advance.

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





This is not possible in PHP, though you can have a Array wrapper class

function returnarray() {
	return new ArrayObject( array('lose' = array(5,6), 'win' = array 
(9,8)) );

}
var_dump (returnarray()-offsetGet('lose'));


or even better make you own wrapper class with __set() and __get()   
methods so you can have


var_dump (returnarray()-lose);

of course only in PHP5


Bojan Tesanovic
http://www.carster.us/






[PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi all,

Just a quick straw-poll really:

What is your take on using 'return' when you end a function, if you
don't actually need to return a value?

If you have to return say a true/false as the result of an operation,
then it's an obvious choice. But what if all the function does is
perform an action and then quit? Do you like to use 'return' at the
end of it anyway, or do you just let it run into the closing } ?

Or do you perhaps do a 'return true' at the end, regardless, even if
the rest of your code never checks that value (on the basis that it
may do in the future)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

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



RE: [PHP] Return or not to return, that is the question

2007-05-30 Thread Edward Kay


 Just a quick straw-poll really:
 
 What is your take on using 'return' when you end a function, if you
 don't actually need to return a value?
 
 If you have to return say a true/false as the result of an operation,
 then it's an obvious choice. But what if all the function does is
 perform an action and then quit? Do you like to use 'return' at the
 end of it anyway, or do you just let it run into the closing } ?
 
 Or do you perhaps do a 'return true' at the end, regardless, even if
 the rest of your code never checks that value (on the basis that it
 may do in the future)
 

I like to have all my functions return something so use return true.

Edward

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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Dave Goodchild

If there is no need to return a value then I don't do so. However, the
function is going to process something, and surely you should check that the
processing has succeeded or failed?


Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Dave,

Wednesday, May 30, 2007, 12:20:48 PM, you wrote:

 If there is no need to return a value then I don't do so. However, the
 function is going to process something, and surely you should check that the
 processing has succeeded or failed?

I have exception and error handling dealt with fully in my functions,
by which stage the 'return' at the end becomes redundant because the
return value doesn't need checking as the error handler has already
taken over. However take the following:

$result = $this-calculateSomething($value);

If 'calculateSomething' has all the error handling it requires built
into it, then isn't checking the value of 'result' superfluous to
requirements? Yet even so, I still like to return something at the end
regardless :)

I guess another way to phrase the same question would be where do you
shift all of your error handling - inside the function itself, or in
the code that calls it (i.e. checking the $result in the example
above). Personally I handle it all in the function otherwise I'm
duplicating masses of result checking.

It isn't a case of wrong/right, just trying to gauge preferences here.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Scott

On Wed, 2007-05-30 at 12:20 +0100, Dave Goodchild wrote:
 If there is no need to return a value then I don't do so. However, the
 function is going to process something, and surely you should check that the
 processing has succeeded or failed?

If you unit test, then returns become quite important, so I almost
always return;

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm 

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

Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Zoltán Németh
2007. 05. 30, szerda keltezéssel 11.52-kor Richard Davey ezt írta:
 Hi all,
 
 Just a quick straw-poll really:
 
 What is your take on using 'return' when you end a function, if you
 don't actually need to return a value?
 
 If you have to return say a true/false as the result of an operation,
 then it's an obvious choice. But what if all the function does is
 perform an action and then quit? Do you like to use 'return' at the
 end of it anyway, or do you just let it run into the closing } ?
 
 Or do you perhaps do a 'return true' at the end, regardless, even if
 the rest of your code never checks that value (on the basis that it
 may do in the future)

personally I prefer to use return only if I need the return value for
something. If it's not used then I think it's just a waste of code lines
and resources to return anything...

greets
Zoltán Németh

 
 Cheers,
 
 Rich
 -- 
 Zend Certified Engineer
 http://www.corephp.co.uk
 
 Never trust a computer you can't throw out of a window
 

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



RE: [PHP] Return or not to return, that is the question

2007-05-30 Thread Chris Boget
 If there is no need to return a value then I don't do 
 so. However, the function is going to process something, 
 and surely you should check that the processing has 
 succeeded or failed?

This is precisely the point I was going to make.  Unless an argument is
passed in by reference for manipulation within the function, I can't
think of a reason why you wouldn't want to return a value; true or false
at the very least.  You call a function to perform, well, a function.  I
would think that you would want to know whether or not the process
within the function was successful, yes?

thnx,
Chris

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



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Chris,

Wednesday, May 30, 2007, 1:17:39 PM, you wrote:

 If there is no need to return a value then I don't do 
 so. However, the function is going to process something, 
 and surely you should check that the processing has 
 succeeded or failed?

 This is precisely the point I was going to make.  Unless an argument is
 passed in by reference for manipulation within the function, I can't
 think of a reason why you wouldn't want to return a value; true or false
 at the very least.  You call a function to perform, well, a function.  I
 would think that you would want to know whether or not the process
 within the function was successful, yes?

Even the most simple function can have more than one failure point
within it. If you aren't handling the errors yourself within the
function, you're returning false all over the place and then having to
do the same checking from whatever called it - duplicated however many
times you call that function from your code.

It's a hideous example, but it's straight out of the PHP manual, so
run with it and indulge me:

$mysqli = new mysqli(localhost, my_user, my_password, world);

/* check connection */
if (mysqli_connect_errno()) {
printf(Connect failed: %s\n, mysqli_connect_error());
exit();
}

If that was wrapped in a function, sticking 'return false' within the
connect_error check is useful why exactly? Equally the fact the
function didn't 'exit' implies it 'returned true' anyway, so why check
it again in whatever called the function in the first place? it has
performed its task, it didn't raise an error.

(I know most of us would never use 'exit' in production code like the
above, so replace it with whatever error handling mechanism you have,
the question above remains the same.)

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Darren Whitlen

Chris Boget wrote:
If there is no need to return a value then I don't do 
so. However, the function is going to process something, 
and surely you should check that the processing has 
succeeded or failed?


This is precisely the point I was going to make.  Unless an argument is
passed in by reference for manipulation within the function, I can't
think of a reason why you wouldn't want to return a value; true or false
at the very least.  You call a function to perform, well, a function.  I
would think that you would want to know whether or not the process
within the function was successful, yes?

thnx,
Chris


All depends on the function.

function someFunc(){
$this-counter++;
if($this-counter  100) $this-counter = 0;
}


Something that simple wont need a return at all.

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



RE: [PHP] Return or not to return, that is the question

2007-05-30 Thread Jay Blanchard
[snip]
All depends on the function.

function someFunc(){
$this-counter++;
if($this-counter  100) $this-counter = 0;
}


Something that simple wont need a return at all.
[/snip]

Classically this would need a return, because $this-counter is going to
be less than 100 most of the time, and you may want to return the value
at some point.

Here is the thing (it is akin to all of the holy wars on brackets, etc),
the use of return has been pounded into old-schoolers heads for a long
time, regardless of the Boolean or value returned. It is good style and
it introduces consistency. As far as it being an extra line of code? So
be it! We're not in the day and age where we had to count CPU cycles! If
anyone is designing PHP applications with that level of granularity they
have entered into an amazingly pedantic process for which PHP is not
well suited.

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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 5:52 am, Richard Davey wrote:
 Just a quick straw-poll really:

 What is your take on using 'return' when you end a function, if you
 don't actually need to return a value?

 If you have to return say a true/false as the result of an operation,
 then it's an obvious choice. But what if all the function does is
 perform an action and then quit? Do you like to use 'return' at the
 end of it anyway, or do you just let it run into the closing } ?

 Or do you perhaps do a 'return true' at the end, regardless, even if
 the rest of your code never checks that value (on the basis that it
 may do in the future)

Planning for a return value that you might need but have no idea what
it will be is probably a Bad Idea -- You'll just need to document it,
maintain it, etc for no real reason.

If the function is only called for side-effects (I.e., it returns
nothing) then don't return anything -- You'll know by looking at the
end of the function that it's not supposed to return anything.

Adding the gratuitous 'return' seems of dubious benefit.

I rarely write a function that doesn't return anything, come to think
of it...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Novitski

At 5/30/2007 05:41 AM, Richard Davey wrote:

/* check connection */
if (mysqli_connect_errno()) {
printf(Connect failed: %s\n, mysqli_connect_error());
exit();
}

If that was wrapped in a function, sticking 'return false' within the
connect_error check is useful why exactly? Equally the fact the
function didn't 'exit' implies it 'returned true' anyway, so why check
it again in whatever called the function in the first place? it has
performed its task, it didn't raise an error.

(I know most of us would never use 'exit' in production code like the
above, so replace it with whatever error handling mechanism you have,
the question above remains the same.)



I demur at your final point:  If we don't use exit() and the function 
performs non-aborting error handling, it's going to return to the 
calling function which in most cases will need to know whether its 
child function succeeded or failed.


In most of the applications I write, an SQL error (not merely an 
empty result set) indicates more often than not that the parent code 
should gracefully withdraw from the process it was attempting to 
perform.  SQL errors are going to indicate a syntactical error in the 
query, a missing table or field, a connection failure, or another 
problem serious enough that the developer's attention should be drawn 
to it.  It's certainly possible in a thoughtfully-written application 
for a parent function not to care whether a child SQL query was 
successful on this fundamental level, but in most apps we'll want to know.


function parent()
{
lookUpData();
displayData();
}
function lookUpData()
{
set up query;
execute query;
handle errors;
}

where handle errors might range from returning a failure flag to 
displaying an error message.


In order that displayData() doesn't fall on its face, I would write 
the parent function in one of these ways:


if (lookUpData()) displayData();

in which lookUpData() returns true or false, the record set being 
passed in a global variable (ugh);


or, if displayData() is smart enough to deal intelligently with a 
null or empty result set:


$aResultSet = lookUpData();
displayData($aResultSet);
or:
displayData(lookUpData());

in which lookUpData() returns a dataset array that's empty if no 
records were found or an error was encountered.


In my programming style, I can't imagine wanting to write this code 
in such a way that lookUpData() didn't return some form of success or 
error indicator.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Davey
Hi Paul,

Wednesday, May 30, 2007, 4:07:00 PM, you wrote:

 I demur at your final point:  If we don't use exit() and the function
 performs non-aborting error handling, it's going to return to the 
 calling function which in most cases will need to know whether its 
 child function succeeded or failed.

  function parent()
  {
  lookUpData();
  displayData();
  }
  function lookUpData()
  {
  set up query;
  execute query;
  handle errors;
  }

 where handle errors might range from returning a failure flag to 
 displaying an error message.

There's a world of difference between those two events though. If all
'handle errors' does is to return an error flag, then the parent
obviously *needs* to check it. Equally all other functions that ever
call lookUpData() need to duplicate those checks too.

 In order that displayData() doesn't fall on its face, I would write
 the parent function in one of these ways:

  if (lookUpData()) displayData();

That's where our approach differs. If lookUpData falls flat on its
face, my error handler will take over completely, finally resulting in
an 'abortive' event, and never pass back to the parent. If an error is
of a critical enough nature the system needs to stop. If it's not
critical then the error handling within displayData() would detect it
has nothing to display and error in its own accord.

 In my programming style, I can't imagine wanting to write this code
 in such a way that lookUpData() didn't return some form of success or 
 error indicator.

That's a *very* specific example though. My question was do people
place a 'return' statement at the end of **ALL** of their functions,
regardless of what that function actually did. In the code you gave
there is a fair argument both ways, but that isn't always the case.

Here's a piss-poor example off the top of my head:

function parent()
{
 display()
}

function display()
{
 echo something random
}

In this instance (albeit gloriously simple / useless), would your
display() return true even though it could have never actually failed?
and if it did, do you then care about checking that value in the
parent?

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

Never trust a computer you can't throw out of a window

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



Re: Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 10:25 am, Richard Davey wrote:
 Hi Paul,

 Wednesday, May 30, 2007, 4:07:00 PM, you wrote:

 I demur at your final point:  If we don't use exit() and the
 function
 performs non-aborting error handling, it's going to return to the
 calling function which in most cases will need to know whether its
 child function succeeded or failed.

  function parent()
  {
  lookUpData();
  displayData();
  }
  function lookUpData()
  {
  set up query;
  execute query;
  handle errors;
  }

 where handle errors might range from returning a failure flag to
 displaying an error message.

 There's a world of difference between those two events though. If all
 'handle errors' does is to return an error flag, then the parent
 obviously *needs* to check it. Equally all other functions that ever
 call lookUpData() need to duplicate those checks too.

 In order that displayData() doesn't fall on its face, I would write
 the parent function in one of these ways:

  if (lookUpData()) displayData();

 That's where our approach differs. If lookUpData falls flat on its
 face, my error handler will take over completely, finally resulting in
 an 'abortive' event, and never pass back to the parent. If an error is
 of a critical enough nature the system needs to stop. If it's not
 critical then the error handling within displayData() would detect it
 has nothing to display and error in its own accord.

This sounds perfectly reasoanble.

 In my programming style, I can't imagine wanting to write this code
 in such a way that lookUpData() didn't return some form of success
 or
 error indicator.

 That's a *very* specific example though. My question was do people
 place a 'return' statement at the end of **ALL** of their functions,
 regardless of what that function actually did. In the code you gave
 there is a fair argument both ways, but that isn't always the case.

 Here's a piss-poor example off the top of my head:

 function parent()
 {
  display()
 }

 function display()
 {
  echo something random
 }

 In this instance (albeit gloriously simple / useless), would your
 display() return true even though it could have never actually failed?
 and if it did, do you then care about checking that value in the
 parent?

Technically, there is no such thing as could have never actually
failed...

It's not outside the realm of possibility that:
echo something random;
could actually fail...

In all the ways I can think of, PHP would never actually return, but
there's no guarantee that won't change under the hood tomorrow...

I'm not saying that every scripter should worry about this; but if you
have a mission-critical application in PHP, you should probably go
ahead and return true/false on success/failure of every function, no
matter how trivial it may seem.

But for your basic website, no, you don't need that level of
robustness -- The Internet itself will cause so many failures that
your lack of error-checking for something that rare will be lost as
noise in any sort of statistical error model.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 12:00 pm, Paul Novitski wrote:
[snip] use the archives

I think there is a LOT of value in bubbling up errors to the
appropriate level of handling, and letting the right layer do the
right job for the error.

HOWEVER: it is not a good idea, imho, to always let the errors
bubble up to the outer layer, which is what Paul seemed to have
typed...

The problem with that approach is that you end up being painted into a
corner where your application can do little more than print It
broke. because the low-level context is not available to the caller
of the function.

The lowest layers of your application should be logging very precise
info about the error for the developer, with code for every possible
error condition you can think of, and hopefully defaults for error
conditions you can't think of.

The middle layers might return a smaller set of common error
codes/messages.

The outer layer might lookup error codes to print suitable end-user
messages, or translate with gettext or...

In an ideal world, the outer layer presents the end user with
something meaningful to them, while providing an error code or unique
identifier that a developer can use to locate the detailed info needed
to fix the problem.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 7:42 am, Darren Whitlen wrote:
 Chris Boget wrote:
 If there is no need to return a value then I don't do
 so. However, the function is going to process something,
 and surely you should check that the processing has
 succeeded or failed?

 This is precisely the point I was going to make.  Unless an argument
 is
 passed in by reference for manipulation within the function, I can't
 think of a reason why you wouldn't want to return a value; true or
 false
 at the very least.  You call a function to perform, well, a
 function.  I
 would think that you would want to know whether or not the process
 within the function was successful, yes?

I guess if you're using lots of OOP and try/catch/throw, you'd end up
very rarely having a function return a pass/fail value...

Just depends on coding style, I guess.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Novitski

At 5/30/2007 08:25 AM, Richard Davey wrote:

 In order that displayData() doesn't fall on its face, I would write
 the parent function in one of these ways:

  if (lookUpData()) displayData();

That's where our approach differs. If lookUpData falls flat on its
face, my error handler will take over completely, finally resulting in
an 'abortive' event, and never pass back to the parent. If an error is
of a critical enough nature the system needs to stop. If it's not
critical then the error handling within displayData() would detect it
has nothing to display and error in its own accord.


Hi Richard,

If you write your applications like this then they'll fall over when 
something goes wrong -- and here I mean 'fall over' to mean aborting 
suddenly with a technical error message.  That can be useful to us 
during development  debugging but isn't really useful or friendly to 
the website visitor.


It also gives every subroutine that handles errors the responsibility 
of deciding how to deal with the error -- whether to display it or 
not, how to display it, etc.  It makes code less portable from one 
application to the next.


Consider another model in which subroutines report errors back to the 
calling code but don't themselves 'act' on the errors.  An error on a 
low level can bubble back up to some higher parent level in the 
application that knows what to do:  whether to display and if so how 
and in what human language, whether to email the developer, whether 
to close down the application or continue, etc.  An English SQL error 
message is of little use to a web page in Japanese.  It's usually a 
mistake to display an SQL query in a public application because it 
exposes sensitive details of the database architecture.


For example, we might want to generate the web page even if some part 
of its content is unavailable due to the SQL error.  This leaves the 
visitor with a functional page from which they can navigate normally 
even if part of the content is missing.  On this high level, the 
application might choose to behave nonchalantly as though SQL had 
returned an empty recordset and report the hard error to the 
webmaster behind the scenes.


This kind of error-handling architecture can be handled in a variety 
of ways.  One is to maintain a global error structure or class with a 
variety of fields that relate to the last error: true/false, error 
type, context, query code if applicable, etc.  Because a low-level 
error may in turn trigger higher-level errors as it bubbles back up, 
it may make sense to turn this into an error stack to which each 
calling function adds its understanding of the problem as the error 
bubbles back up:


0: SQL error ZZZ in SELECT * FROM `users` ...
1: Can't query user list YYY
2: No users to display

When a high-level function receives an error state from a called 
function, it can (if desired) walk down the stack to learn the 
technical origin of the error as well as its implications during the bubble-up.




 In my programming style, I can't imagine wanting to write this code
 in such a way that lookUpData() didn't return some form of success or
 error indicator.

That's a *very* specific example though. My question was do people
place a 'return' statement at the end of **ALL** of their functions,
regardless of what that function actually did. In the code you gave
there is a fair argument both ways, but that isn't always the case.


Absolutely.  I agree with most of the respondents to this thread: 
return a value only if the caller needs to receive a value 
back.  Some languages (such as BASIC) distinguish between functions 
that return values and subroutines that don't.  Because PHP gives 
only one type of function to call, with an option whether or not to 
return anything, it's clearly up to us to design and impose that 
architecture based on our knowledge and preferences.


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



RE: [PHP] Return or not to return, that is the question

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 7:56 am, Jay Blanchard wrote:
 Classically this would need a return, because $this-counter is going
 to
 be less than 100 most of the time, and you may want to return the
 value
 at some point.

Or you may not ever need to return it.

And if you return it for no reason, you have to document what the
function returns, maintain it as returning that, and can never decide
to return something else more useful tomorrow, when you find out what
you actually need to return.

 Here is the thing (it is akin to all of the holy wars on brackets,
 etc),
 the use of return has been pounded into old-schoolers heads for a long
 time, regardless of the Boolean or value returned. It is good style
 and
 it introduces consistency. As far as it being an extra line of code?
 So
 be it! We're not in the day and age where we had to count CPU cycles!
 If
 anyone is designing PHP applications with that level of granularity
 they
 have entered into an amazingly pedantic process for which PHP is not
 well suited.

As I recall, the reasons for always returning something in C are
pretty irrelevant to PHP...

I think there was a time when (void) was not a valid return data type,
so you HAD to return at least an (int) -- and programmers would start
to rely on the essentially random value being returned always being 0
when it wasn't going to always be 0 -- it just happened to always be 0
due to that was what was always in the byte on the stack... Until you
changed your code and the whole thing went to the toilet because of
the assumption about what was being returned.

PHP and C have many similarities, but that doesn't mean that every
Best Practice is going to transfer over, because they are very very
different languages.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Paul Novitski

At 5/30/2007 10:51 AM, Richard Lynch wrote:

On Wed, May 30, 2007 12:00 pm, Paul Novitski wrote:
[snip] use the archives


Good suggestion!



HOWEVER: it is not a good idea, imho, to always let the errors
bubble up to the outer layer, which is what Paul seemed to have
typed...


But didn't.



The problem with that approach is that you end up being painted into a
corner where your application can do little more than print It
broke. because the low-level context is not available to the caller
of the function.


If you'll refer back to my posting to which you're replying without 
quoting, you'll read:


At 5/30/2007 10:00 AM, Paul Novitski wrote:
Because a low-level error may in turn trigger higher-level errors as 
it bubbles back up, it may make sense to turn this into an error 
stack to which each calling function adds its understanding of the 
problem as the error bubbles back up:

...
When a high-level function receives an error state from a called 
function, it can (if desired) walk down the stack to learn the 
technical origin of the error as well as its implications during the bubble-up.


It sounds like we're on the same page, Richard!

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: Re[2]: [PHP] Return or not to return, that is the question

2007-05-30 Thread Philip Thompson

On May 30, 2007, at 6:32 AM, Richard Davey wrote:


Hi Dave,

Wednesday, May 30, 2007, 12:20:48 PM, you wrote:

If there is no need to return a value then I don't do so. However,  
the
function is going to process something, and surely you should  
check that the

processing has succeeded or failed?


I have exception and error handling dealt with fully in my functions,
by which stage the 'return' at the end becomes redundant because the
return value doesn't need checking as the error handler has already
taken over. However take the following:

$result = $this-calculateSomething($value);

If 'calculateSomething' has all the error handling it requires built
into it, then isn't checking the value of 'result' superfluous to
requirements? Yet even so, I still like to return something at the end
regardless :)


I normally (but not always) return (whether I will actually use that  
value or not).




I guess another way to phrase the same question would be where do you
shift all of your error handling - inside the function itself, or in
the code that calls it (i.e. checking the $result in the example
above). Personally I handle it all in the function otherwise I'm
duplicating masses of result checking.


I spent some time thinking about this exact question and I came up  
with several things:


1. How does PHP do it?

They have a function which performs whatever and returns an error  
(code) upon failing. This allows every developer to deal with the  
error in their own way.


2. Does this function need to be portable? (Short answer, yes, it  
*should* be.)


Take these functions for example:

?
function doSomethingToA ($a)
{
   if (!$a) $_SESSION[not_portable] = false;
   else $_SESSION[not_portable] = true;
   return; // optional
}

function doSomethingToB ($b)
{
   if (!$b) return false;
   else return true;
}

// Non-portable function that probably won't work outside this  
application

doSomethingToA ($_SESSION[whatever]);

// Portable function that you can take anywhere! =D
$_SESSION[portable] = doSomethingToB ($_SESSION[whatever]);
?

Yes, you may have to do some more error-checking on the outside of  
the function. However, the question comes down to... what's your use  
for it. It's almost a religious question - it's up to you on how you  
code. Just be sure to weigh all the options.


~Philip



It isn't a case of wrong/right, just trying to gauge preferences here.

Cheers,

Rich


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



[PHP] [SOLVED] [PHP] return bounced email to specific email address

2007-01-31 Thread afan
 [EMAIL PROTECTED] wrote:
 hi,
 is it possible to specify email address in mail() function where bounced
 email could return?

 I checked http://us2.php.net/manual/en/function.mail.php but didn't find
 anything.

 That's the right place. It's the 5th parameter you want to change.

 --
 Postgresql  php tutorials
 http://www.designmagick.com/


yesterday somebody posted really good explanation about this
:)

Thanks.

-afan

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



Re: [PHP] return bounced email to specific email address

2007-01-31 Thread Richard Lynch
On Tue, January 30, 2007 9:44 am, [EMAIL PROTECTED] wrote:
 is it possible to specify email address in mail() function where
 bounced
 email could return?

 I checked http://us2.php.net/manual/en/function.mail.php but didn't
 find
 anything.

Some MTAs follow some standards which at one time or another allowed
headers such as:

Error-to: email address

It's not 100%, but works with many MTAs.

There's another header like Bounces-to: or somesuch, I think, that is
in much less widespread use, but may be worth researching.

This is not PHP-specific, so you may want to look more at mailing list
software and how they do it than at PHP functions.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



[PHP] return bounced email to specific email address

2007-01-30 Thread afan
hi,
is it possible to specify email address in mail() function where bounced
email could return?

I checked http://us2.php.net/manual/en/function.mail.php but didn't find
anything.

thanks.

-afan

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



Re: [PHP] return bounced email to specific email address

2007-01-30 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-30 16:44:38 +0100:
 is it possible to specify email address in mail() function where bounced
 email could return?
 
Yes, see ftp://ftp.rfc-editor.org/in-notes/rfc2821.txt

 I checked http://us2.php.net/manual/en/function.mail.php but didn't find
 anything.

That's ok, PHP manual shouldn't duplicate specifications for all kinds
of network protocols or whatnot.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] return bounced email to specific email address

2007-01-30 Thread Chris

[EMAIL PROTECTED] wrote:

hi,
is it possible to specify email address in mail() function where bounced
email could return?

I checked http://us2.php.net/manual/en/function.mail.php but didn't find
anything.


That's the right place. It's the 5th parameter you want to change.

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-08-03 Thread Richard Lynch
On Thu, July 27, 2006 1:05 pm, Adam Zey wrote:
 Then how come when I do a foreach on an array (without modifying
 anything within the foreach), it still makes a copy of the array that
 consumes memory? I think it's dangerous to generalize that it's always
 best to let PHP make copies of things. In the foreach situation, the
 preferred solution when memory is a problem is to either use a
 reference, or have foreach iterate over the keys of the array.

I think this is because you can sometimes use  to modify the contents
of the iteratee (is that a word?) so PHP does a copy there blindly,
whether you have  or not, because you might have  there sometimes.

I think Dmitry or Antony or ??? is looking at changing that so the
copy is only done when  is present.

At least, that's how I understand (or not) the upshot of a thread on
Internals.

It's entirely possible, even likely, that I'm completely
misunderstanding both of these threads. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-07-27 Thread Robert Cummings
On Thu, 2006-07-27 at 01:35, Larry Garfield wrote:
 On Wednesday 26 July 2006 21:41, Robert Cummings wrote:
 
   I'm working on some code that would be called to generate a cell in a
   possibly large table and therefore a small difference in performance
   may have a significant impact.
 
  PHP uses copy-on-write and so copies are essentially shared until such
  time as you modify one of them. If you don't need references then copies
  are faster than references.
 
 By the same token, then, if I have a function that generates a large string 
 and returns it, is there any benefit to return-by-reference?

Nope. You should only use references if you really need them. Attempting
to improve efficiency by using references instead of copies when you
aren't actually in need of a reference will result in less efficiency
since the engine spends more time creating the reference than the copy.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-07-27 Thread Adam Zey

Robert Cummings wrote:

On Thu, 2006-07-27 at 01:35, Larry Garfield wrote:

On Wednesday 26 July 2006 21:41, Robert Cummings wrote:


I'm working on some code that would be called to generate a cell in a
possibly large table and therefore a small difference in performance
may have a significant impact.

PHP uses copy-on-write and so copies are essentially shared until such
time as you modify one of them. If you don't need references then copies
are faster than references.
By the same token, then, if I have a function that generates a large string 
and returns it, is there any benefit to return-by-reference?


Nope. You should only use references if you really need them. Attempting
to improve efficiency by using references instead of copies when you
aren't actually in need of a reference will result in less efficiency
since the engine spends more time creating the reference than the copy.

Cheers,
Rob.


Then how come when I do a foreach on an array (without modifying 
anything within the foreach), it still makes a copy of the array that 
consumes memory? I think it's dangerous to generalize that it's always 
best to let PHP make copies of things. In the foreach situation, the 
preferred solution when memory is a problem is to either use a 
reference, or have foreach iterate over the keys of the array.


Regards, Adam.

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



RE: [PHP] Return Values Copied? Copied if By Reference?

2006-07-27 Thread KermodeBear
Robert Cummings wrote:

Then how come when I do a foreach on an array (without modifying 
anything within the foreach), it still makes a copy of the array that 
consumes memory? I think it's dangerous to generalize that it's always 
best to let PHP make copies of things. In the foreach situation, the 
preferred solution when memory is a problem is to either use a 
reference, or have foreach iterate over the keys of the array.

Regards, Adam.

-

PHP doesn't seem to make a real copy of data until one of the copies is
modified, making it necessary to create a new set of data. So, it is pretty
smart about that.

Here is a small CLI script that seems to support this:
?php
$a_array = array();
for($i = 0; $i  1; $i++) {
$a_array[] = time(); // Just an arbitrary piece of data
}
echo 'Memory Usage: ' . memory_get_usage() . \n;
echo Making a copy of the array.\n;
$a_copy = $a_array;
echo 'Memory Usage: ' . memory_get_usage() . \n;
echo Modifying the copy:\n;
$a_copy[] = time();
echo 'Memory Usage: ' . memory_get_usage() . \n;
?

On my machine, this displays:
Memory Usage: 640280
Making a copy of the array.
Memory Usage: 640440
Modifying the copy:
Memory Usage: 1106056

-K. Bear

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-07-27 Thread Adam Zey

KermodeBear wrote:

Robert Cummings wrote:

Then how come when I do a foreach on an array (without modifying 
anything within the foreach), it still makes a copy of the array that 
consumes memory? I think it's dangerous to generalize that it's always 
best to let PHP make copies of things. In the foreach situation, the 
preferred solution when memory is a problem is to either use a 
reference, or have foreach iterate over the keys of the array.


Regards, Adam.

-

PHP doesn't seem to make a real copy of data until one of the copies is
modified, making it necessary to create a new set of data. So, it is pretty
smart about that.

Here is a small CLI script that seems to support this:
?php
$a_array = array();
for($i = 0; $i  1; $i++) {
$a_array[] = time(); // Just an arbitrary piece of data
}
echo 'Memory Usage: ' . memory_get_usage() . \n;
echo Making a copy of the array.\n;
$a_copy = $a_array;
echo 'Memory Usage: ' . memory_get_usage() . \n;
echo Modifying the copy:\n;
$a_copy[] = time();
echo 'Memory Usage: ' . memory_get_usage() . \n;
?

On my machine, this displays:
Memory Usage: 640280
Making a copy of the array.
Memory Usage: 640440
Modifying the copy:
Memory Usage: 1106056

-K. Bear


I note that your example doesn't use a foreach loop, which is what my 
post was about.


Some testing shows my original premise was wrong, but it's still 
possible to get PHP to copy the array when it doesn't need to. In this 
case, using a reference can save memory even when a reference isn't 
needed. If you want to modify the original array in the foreach, then it 
is better to step over the array yourself and save memory, or pass the 
foreach a reference to the array to stop it from doing a copy.


I'm just trying to say, I don't think it's always a good idea to rely on 
the language deciding when to copy. Sometimes it's a good idea to use a 
reference to stop the copy if memory is a concern.


Regards, Adam Zey.

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-07-27 Thread Robert Cummings
On Thu, 2006-07-27 at 14:48, Adam Zey wrote:
 KermodeBear wrote:
  Robert Cummings wrote:
  
  Then how come when I do a foreach on an array (without modifying 
  anything within the foreach), it still makes a copy of the array that 
  consumes memory? I think it's dangerous to generalize that it's always 
  best to let PHP make copies of things. In the foreach situation, the 
  preferred solution when memory is a problem is to either use a 
  reference, or have foreach iterate over the keys of the array.
  
  Regards, Adam.
  
  -
  
  PHP doesn't seem to make a real copy of data until one of the copies is
  modified, making it necessary to create a new set of data. So, it is pretty
  smart about that.
  
  Here is a small CLI script that seems to support this:
  ?php
  $a_array = array();
  for($i = 0; $i  1; $i++) {
  $a_array[] = time(); // Just an arbitrary piece of data
  }
  echo 'Memory Usage: ' . memory_get_usage() . \n;
  echo Making a copy of the array.\n;
  $a_copy = $a_array;
  echo 'Memory Usage: ' . memory_get_usage() . \n;
  echo Modifying the copy:\n;
  $a_copy[] = time();
  echo 'Memory Usage: ' . memory_get_usage() . \n;
  ?
  
  On my machine, this displays:
  Memory Usage: 640280
  Making a copy of the array.
  Memory Usage: 640440
  Modifying the copy:
  Memory Usage: 1106056
  
  -K. Bear
 
 I note that your example doesn't use a foreach loop, which is what my 
 post was about.
 
 Some testing shows my original premise was wrong, but it's still 
 possible to get PHP to copy the array when it doesn't need to. In this 
 case, using a reference can save memory even when a reference isn't 
 needed. If you want to modify the original array in the foreach, then it 
 is better to step over the array yourself and save memory, or pass the 
 foreach a reference to the array to stop it from doing a copy.
 
 I'm just trying to say, I don't think it's always a good idea to rely on 
 the language deciding when to copy. Sometimes it's a good idea to use a 
 reference to stop the copy if memory is a concern.

PHP creates a real copy when one of the original arrays changes. This is
the principle of copy-on-write. If you are getting a copy then one of
the arrays changed, so now you really have to choose between a copy and
reference knowing that a reference will affect all arrays to which you
made a reference or a copy which will only affect the copy to which the
change was made. So this returns to my original assertion that you
should only use references when a reference is necessary.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Return Values Copied? Copied if By Reference?

2006-07-26 Thread Michael B Allen
Is a function return value copied? If the value is an integer I suppose
it is but what about a string or an array? If you pass by reference is
the return value still copied?

For example, is this:

  function foo($arr) {
  $arr[] = bar;
  }

faster than this?

  function foo($arr) {
  $arr[] = bar;
  return $arr; // is this copied?
  }

I'm working on some code that would be called to generate a cell in a
possibly large table and therefore a small difference in performance
may have a significant impact.

Thanks,
Mike

-- 
Michael B Allen
PHP Extension for SSO w/ Windows Group Authorization
http://www.ioplex.com/

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-07-26 Thread Robert Cummings
On Wed, 2006-07-26 at 22:29, Michael B Allen wrote:
 Is a function return value copied? If the value is an integer I suppose
 it is but what about a string or an array? If you pass by reference is
 the return value still copied?
 
 For example, is this:
 
   function foo($arr) {
   $arr[] = bar;
   }
 
 faster than this?
 
   function foo($arr) {
   $arr[] = bar;
   return $arr; // is this copied?
   }
 
 I'm working on some code that would be called to generate a cell in a
 possibly large table and therefore a small difference in performance
 may have a significant impact.

PHP uses copy-on-write and so copies are essentially shared until such
time as you modify one of them. If you don't need references then copies
are faster than references.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Return Values Copied? Copied if By Reference?

2006-07-26 Thread Larry Garfield
On Wednesday 26 July 2006 21:41, Robert Cummings wrote:

  I'm working on some code that would be called to generate a cell in a
  possibly large table and therefore a small difference in performance
  may have a significant impact.

 PHP uses copy-on-write and so copies are essentially shared until such
 time as you modify one of them. If you don't need references then copies
 are faster than references.

By the same token, then, if I have a function that generates a large string 
and returns it, is there any benefit to return-by-reference?

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] Return XML using PHP and Content-Type with UTF-8 breaks the UTF-8

2006-07-20 Thread Mathijs

Ray Hauge wrote:

On Wednesday 19 July 2006 09:27, Mathijs wrote:

Hello there,

I Have an problem with UTF-8 and XML.

I Output perfect XML (according to IE, Opera and Firefox).
I use the Content-Type header with text/xml; charset=utf-8.
For some reason this breaks UTF-8 output.
When i remove it it works. But i need the text/xml header.

If i save an document as .xml with the same contents as UTF-8 it works.

Is this a known problem?

Thx in advanced.


I would try just specifying UTF-8 in the XML header, and remove the charset 
from the content-type header, and just have the text/xml.


?xml version=1.0 encoding=utf-8?

HTH



I have tryed this. But this also breaks the UTF-8.
When i put it back to text/html it works like it should :S.

I Realy have no clue anymore.


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0629-1, 07/19/2006
Tested on: 7/20/2006 8:57:39 AM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com

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



Re: [PHP] Return XML using PHP and Content-Type with UTF-8 breaks the UTF-8

2006-07-20 Thread nicolas figaro

Mathijs a écrit :

Hello there,

I Have an problem with UTF-8 and XML.

I Output perfect XML (according to IE, Opera and Firefox).
I use the Content-Type header with text/xml; charset=utf-8.
For some reason this breaks UTF-8 output.
When i remove it it works. But i need the text/xml header.


Hi,
could you check which encoding your script is saved with ?
I saw some strange things when printing some iso-8859 strings with a php 
script

saved in utf-8.

N F

If i save an document as .xml with the same contents as UTF-8 it works.

Is this a known problem?

Thx in advanced.




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

[PHP] Return XML using PHP and Content-Type with UTF-8 breaks the UTF-8

2006-07-19 Thread Mathijs

Hello there,

I Have an problem with UTF-8 and XML.

I Output perfect XML (according to IE, Opera and Firefox).
I use the Content-Type header with text/xml; charset=utf-8.
For some reason this breaks UTF-8 output.
When i remove it it works. But i need the text/xml header.

If i save an document as .xml with the same contents as UTF-8 it works.

Is this a known problem?

Thx in advanced.

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



Re: [PHP] Return XML using PHP and Content-Type with UTF-8 breaks the UTF-8

2006-07-19 Thread Ray Hauge
On Wednesday 19 July 2006 09:27, Mathijs wrote:
 Hello there,

 I Have an problem with UTF-8 and XML.

 I Output perfect XML (according to IE, Opera and Firefox).
 I use the Content-Type header with text/xml; charset=utf-8.
 For some reason this breaks UTF-8 output.
 When i remove it it works. But i need the text/xml header.

 If i save an document as .xml with the same contents as UTF-8 it works.

 Is this a known problem?

 Thx in advanced.

I would try just specifying UTF-8 in the XML header, and remove the charset 
from the content-type header, and just have the text/xml.

?xml version=1.0 encoding=utf-8?

HTH

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
www.americanstudentloan.com
1.800.575.1099

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



Re: [PHP] return a formatted difference between two dates

2006-04-18 Thread Richard Lynch
On Mon, April 17, 2006 8:55 pm, tedd wrote:
 As I understand it, it won't make any difference if you use
 strtotime()

 See: http://www.weberdev.com/strtotime

Errr, yeah.

Only problem is, he needs non-existent function that might be named
timetostr which takes an elapsed time and turns it into a string
like 1 week and 3 days

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] return a formatted difference between two dates

2006-04-17 Thread Richard Lynch
On Fri, April 14, 2006 1:24 pm, jonathan wrote:
 is there a function to take a second count and return it as a
 formatted difference?

 like a date_diff('H hours i',6133)

 that uses date()'s formatting.

I think he means something not unlike:

function human_time($seconds){
  $result =  and  . ($seconds % 60) .  seconds;
  $seconds = floor($seconds/60);

  $result = ($seconds % 60)  minutes $result;
  $seconds = floor($seconds/60);

  $result = ($seconds % 24)  hours $result;
  $seconds = floor($seconds/24);

  $result = ($seconds % 30)  days $result;
  $seconds = floor($seconds/365);

  $result = ($seconds % 12)  months $result;
  $seconds = floor($seconds/12);

  $result = $seconds years $result;

  return $result;
}

That, however, is probably not precisely what he wants, as it's WAY
off in the months/years thing... :-)

This WOULD be a nice function to have built-in, but, unfortunately, a
big ol' can of worms is opened up for the months and at 365+ days --
namely that without a start-time, you can't tell how many years have
passed because you won't know if it was a leap year or not...

One has to wonder WHAT our ancestors where thinking when they decided
to make months have different lengths days and this whole leap year
thing...  I mean, the cure is worse than the disease, no?  Don't even
get me started on daylight savings and 15 minute time-zones. :-)

So maybe it could take an optional start-time and assuming dates in
the Unix-time range of 1/1/1970 to MAX_INT do a credible job of it.

Then you'd need directives sort of like date() has for whether to
print out, say, XX seconds if the number is evenly divisible by 60,
or whether to use 0, space, or no prefix for numbers  10, plus...

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] return a formatted difference between two dates

2006-04-17 Thread tedd

At 6:17 PM -0500 4/17/06, Richard Lynch wrote:

On Fri, April 14, 2006 1:24 pm, jonathan wrote:

 is there a function to take a second count and return it as a

  formatted difference?



That, however, is probably not precisely what he wants, as it's WAY
off in the months/years thing... :-)

This WOULD be a nice function to have built-in, but, unfortunately, a
big ol' can of worms is opened up for the months and at 365+ days --
namely that without a start-time, you can't tell how many years have
passed because you won't know if it was a leap year or not...


As I understand it, it won't make any difference if you use strtotime()

See: http://www.weberdev.com/strtotime

That's a neat function because it's usually smarter (with respect to 
date) than the person who is using it. For example, you can add 60 
days to Jan 1 and it will give you March 1 unless it's a leap year 
where it gives you February 29 -- neat huh? (I hope my math is right).



One has to wonder WHAT our ancestors where thinking when they decided
to make months have different lengths days and this whole leap year
thing...  I mean, the cure is worse than the disease, no?  Don't even
get me started on daylight savings and 15 minute time-zones. :-)


Oh, now you got me started. :-)

NOTE: Nothing below is PHP related -- so stop reading NOW -- unless 
you have the time, or want to learn about it.


tedd's rant

You wonder about our ancestors?

Our ancestors were pretty smart with respect to time. As far back as 
15,000 years ago, they were detecting and predicting the Equinox 
(i.e., Stonehenge). 10,000 years ago, they computed the age of the 
universe (get this) to be 15 billion years old (way to go Buddhist 
monks). 5000 years ago, they detected the Precession of the Earth, 
which takes 26,000 years to revolve (way to go American Indian). 4000 
years ago, an Egyptian figured the circumstance of the Earth within 
less than a 5% error and his culture built Pyramids that were square 
within 1/4 inch (sorry not time related). Back to point, the Incas 
had calendars that accurately predicted solar and lunar eclipses far 
into the future (some say they still work).


As for the Western calendar, I agree it's has been a bit hard to 
compute -- but there are reasons why. Our ancestors were faced with 
something that isn't easily resolved as one becomes more and more 
accurate measuring time passing -- like the day of the week for 
example.


First of all, we ought to stop at year 1583. Prior to that, the day 
of the week cannot be calculated (it can -- but the algorithm is very 
complex).


In order to understand why we can't calculate the week day, we need 
to look at the calendar history.


Prior to Julius Caesar (100-44 B.C) ruling Rome the Roman year was 
354 days long. When Julius came to power (49-45 B.C.), one of his 
first challenge was to appease the farmers who complained big time 
because according to their calendar it was spring time and time to 
sow/plant but actually it was mid winter.


Julius hired Sosigenes of Alexandria (a mathematician) to figure out 
what went wrong. A tub of wine and a couple of girls later, Sosigenes 
suggested that the length of the year was wrong. It should have been 
365.25 days. The extra .25 day after four years became the extra day 
added in February.


Julius made a mess of 46 B.C. by adding a couple of months (he made 
money on taxes --BIG time) making 46 B.C. 445 days long!


Of course, Sosigenes, not having a calculator, didn't realize that a 
solar year is really 365.2428935 -- his calculations were too large 
by 10 minutes and some seconds for a year (not bad for manual 
computation back in 46 B.C.!)


This error after 1600 years, added up to about 11 days. This was 
detected by astronomers who noticed that the vernal equinox (when 
light and dark periods are equal in length) occurring on March 21 was 
becoming earlier and earlier and in 1582 it was on March 10.


Christopher Clarius, an astronomer, went to Pope Gregory XIII and 
addressed the concern. After seeing all the calculations for 7 
months, pope Gregory knocked off 11 days on October 4, 1582.


The next day, he decreed to be October 15 (so October 5-14 in the 
year 1582 didn't exist), but to not upset the Jews with their 
Sabbath, the day of the week was NOT changed. To avoid this error 
again after 1500 years, Pope Gregory, decreed that every 4 years a 
day will be added. However, on a turn of the century, it will only be 
added if it's divisible by 400. Hence, although year 2000 was a leap 
year -- year 1900 was not. SO, the proper test for a leap year:


A leap year is IF the year is evenly divisible by 4 AND is not the 
turn of the century. IF it is, it must be evenly divisible by 400 -- 
neat huh?


Did you know that this year (2006) we even added a leap second -- you 
don't want to know the computations for that.


It's difficult for anyone to do anything with 365.2428935(more to 
follow) days a year.


So, even now, we couldn't do 

RE: [PHP] return a formatted difference between two dates

2006-04-14 Thread Jay Blanchard
[snip]
is there a function to take a second count and return it as a  
formatted difference?

like a date_diff('H hours i',6133)

that uses date()'s formatting.
[/snip]

http://www.php.net/mktime

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



Re: [PHP] return path of mail function

2006-04-03 Thread Curt Zirzow
On Sun, Apr 02, 2006 at 10:34:48PM -0700, [EMAIL PROTECTED] wrote:
 The same as before:
 
 Return-path: [EMAIL PROTECTED]
 Envelope-to: [EMAIL PROTECTED]
 Delivery-date: Mon, 03 Apr 2006 00:35:34 -0500
 Received: from nobody by amsterdam.servershost.net with local (Exim 4.52)
 
Exim probably isn't allowing it for security reasons.

 ...
 the
   code as below:
  
   $return=test@test.com;
   $orig_sendmail_from = ini_get('sendmail_from');
   ini_set('sendmail_from', $return);

You are better off using the 5th paramater to mail() instead..

 mail($to, $sub, $msg, $headers, -f $return);


The return-path shouldn't nor will be allowed in your standard
$headers var.


Curt.
-- 
cat .signature: No such file or directory

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



Re: [PHP] return path of mail function

2006-04-03 Thread sub

 You are better off using the 5th paramater to mail() instead..
  mail($to, $sub, $msg, $headers, -f $return);


And what if that doesn't work? Is there a 3rd way of doing it that might
work?

~Drew

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



Re: [PHP] return path of mail function

2006-04-03 Thread Chris

[EMAIL PROTECTED] wrote:

You are better off using the 5th paramater to mail() instead..
mail($to, $sub, $msg, $headers, -f $return);




And what if that doesn't work? Is there a 3rd way of doing it that might
work?


Ask your host if they allow you to change it on the fly. Explain what 
you're trying to do.


As Curt said, they might not let you in their exim config. Not much we 
can do if that's the case..



--
Postgresql  php tutorials
http://www.designmagick.com/

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



[PHP] return path of mail function

2006-04-02 Thread Andrew Darrow
I'm having a problem setting the return-path using the mail function. I seem to 
be able to modify any of the other header information I want, but not this one 
item. 

Here's my code:
$headers =  Return-Path: Test test@test.com\r\n .
   From: Test test@test.com\r\n .
   Reply-To: Test test@test.com\r\n;

$sub=Test sub;
$msg=Test msg;

$to=[EMAIL PROTECTED];

mail($to, $sub, $msg, $headers, '-f test@test.com');




And here's the headers that come in: 
Return-path: [EMAIL PROTECTED]
Envelope-to: [EMAIL PROTECTED]
Delivery-date: Sun, 02 Apr 2006 15:19:45 -0500
Received: from nobody by amsterdam.servershost.net with local (Exim 4.52)
 id 1FQ933-00082V-8q
 for [EMAIL PROTECTED]; Sun, 02 Apr 2006 15:19:45 -0500
To: [EMAIL PROTECTED]
Subject: Test sub
X-PHP-Script: www.drewpydraws.com/crap.php for ip address
From: Test test@test.com
Reply-To: Test test@test.com
Message-Id: [EMAIL PROTECTED]
Date: Sun, 02 Apr 2006 15:19:45 -0500
X-Antivirus: AVG for E-mail 7.1.385 [268.3.4/299]
Mime-Version: 1.0
Content-Type: text/plain

The From and Reply-To get set correctly so it works fine on e-mail clients, 
but some of the messages will be delievered to cell phones that display the 
return-path instead of from and reply-to. 

Any thoughts on how I would go about setting the value for Return-Path?

~Drew
www.drewpydraws.com

Re: [PHP] return path of mail function

2006-04-02 Thread Chris

Andrew Darrow wrote:
I'm having a problem setting the return-path using the mail function. I seem to be able to modify any of the other header information I want, but not this one item. 


Here's my code:
$headers =  Return-Path: Test test@test.com\r\n .
   From: Test test@test.com\r\n .
   Reply-To: Test test@test.com\r\n;

$sub=Test sub;
$msg=Test msg;

$to=[EMAIL PROTECTED];

mail($to, $sub, $msg, $headers, '-f test@test.com');


No space between -f and the email.

I assume your host doesn't have safe-mode on? (You can't use this method 
if so).


Check a phpinfo page and look for:

sendmail_from

If that's set, this way won't do it either, you'll need to do:

$orig_sendmail_from = ini_get('sendmail_from');

// this should match what phpinfo tells you but replace the email. so 
might be '-f'.$return_path

ini_set('sendmail_from', $return_path);

mail($to, $sub, $msg, $headers);

and leave off the last parameter.

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] return path of mail function

2006-04-02 Thread Chris

[EMAIL PROTECTED] wrote:

Safe mode is indeed off and sendmail_from has no value. I've modified the
code as below:

$return=test@test.com;
$orig_sendmail_from = ini_get('sendmail_from');
ini_set('sendmail_from', $return);

$headers =  From: Test test@test.com\r\n .
   Reply-To: Test test@test.com\r\n;

$sub=Test sub;
$msg=Test msg;
$to=[EMAIL PROTECTED];

mail($to, $sub, $msg, $headers);


What headers do you get when you do this?

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] return path of mail function

2006-04-02 Thread sub
The same as before:

Return-path: [EMAIL PROTECTED]
Envelope-to: [EMAIL PROTECTED]
Delivery-date: Mon, 03 Apr 2006 00:35:34 -0500
Received: from nobody by amsterdam.servershost.net with local (Exim 4.52)
 id 1FQHiw-Kf-E4
 for [EMAIL PROTECTED]; Mon, 03 Apr 2006 00:35:34 -0500
To: [EMAIL PROTECTED]
Subject: Test sub
X-PHP-Script: www.drewpydraws.com/crap.php for ip address
From: Test test@test.com
Reply-To: Test test@test.com
Message-Id: [EMAIL PROTECTED]
Date: Mon, 03 Apr 2006 00:35:34 -0500
X-Antivirus: AVG for E-mail 7.1.385 [268.3.4/299]
Mime-Version: 1.0
Content-Type: text/plain


~Drew
www.drewpydraws.com
- Original Message - 
From: Chris [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Sunday, April 02, 2006 10:31 PM
Subject: Re: [PHP] return path of mail function


 [EMAIL PROTECTED] wrote:
  Safe mode is indeed off and sendmail_from has no value. I've modified
the
  code as below:
 
  $return=test@test.com;
  $orig_sendmail_from = ini_get('sendmail_from');
  ini_set('sendmail_from', $return);
 
  $headers =  From: Test test@test.com\r\n .
 Reply-To: Test test@test.com\r\n;
 
  $sub=Test sub;
  $msg=Test msg;
  $to=[EMAIL PROTECTED];
 
  mail($to, $sub, $msg, $headers);

 What headers do you get when you do this?


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



Re: [PHP] return path of mail function

2006-04-02 Thread sub
Safe mode is indeed off and sendmail_from has no value. I've modified the
code as below:

$return=test@test.com;
$orig_sendmail_from = ini_get('sendmail_from');
ini_set('sendmail_from', $return);

$headers =  From: Test test@test.com\r\n .
   Reply-To: Test test@test.com\r\n;

$sub=Test sub;
$msg=Test msg;
$to=[EMAIL PROTECTED];

mail($to, $sub, $msg, $headers);

Still doesn't work. I also tried modifying the5th argument as
[EMAIL PROTECTED] and [EMAIL PROTECTED] neither of those worked either.

I'm not sure what i'm missing here. If it would help to view the phpinfo
from my host, you may do so here http://drewpydraws.com/phpinfo.php

~Drew
www.drewpydraws.com

- Original Message - 
From: Chris [EMAIL PROTECTED]
To: Andrew Darrow [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Sunday, April 02, 2006 5:02 PM
Subject: Re: [PHP] return path of mail function


 Andrew Darrow wrote:
  I'm having a problem setting the return-path using the mail function. I
seem to be able to modify any of the other header information I want, but
not this one item.
 
  Here's my code:
  $headers =  Return-Path: Test test@test.com\r\n .
 From: Test test@test.com\r\n .
 Reply-To: Test test@test.com\r\n;
 
  $sub=Test sub;
  $msg=Test msg;
 
  $to=[EMAIL PROTECTED];
 
  mail($to, $sub, $msg, $headers, '-f test@test.com');

 No space between -f and the email.

 I assume your host doesn't have safe-mode on? (You can't use this method
 if so).

 Check a phpinfo page and look for:

 sendmail_from

 If that's set, this way won't do it either, you'll need to do:

 $orig_sendmail_from = ini_get('sendmail_from');

 // this should match what phpinfo tells you but replace the email. so
 might be '-f'.$return_path
 ini_set('sendmail_from', $return_path);

 mail($to, $sub, $msg, $headers);

 and leave off the last parameter.

 -- 
 Postgresql  php tutorials
 http://www.designmagick.com/

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





 -- 
 No virus found in this incoming message.
 Checked by AVG Free Edition.
 Version: 7.1.385 / Virus Database: 268.3.4/299 - Release Date: 3/31/2006



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



[PHP] return node-set to stylesheet via php:function

2006-02-23 Thread kwmccabe

using:  RedHat ; PHP 5.1.2 ; libxml 2.6.22

How do I return a node-set to an xsl stylesheet via php:function?

I've had no difficulty returning strings, but so far xsl refuses to see 
the result as something I can iterate as real XML.



php fragment:
-
// return String
function getNodesOne()
{
   return 'RESULTNODEfoo/NODENODEbar/NODE/RESULT';
}

// return DomDocument
function getNodesTwo()
{
   $xml = 'RESULTNODEfoo/NODENODEbar/NODE/RESULT';
   $doc = DomDocument::loadXML($xml);
   return $doc;
}
-

xsl fragment:
-
xsl:variable name=nodes
   xsl:copy-of select=php:function('getNodes') /
/xsl:variable

cnt=xsl:value-of select=count($nodes/RESULT/NODE) /
-

expected result: 
   cnt=2


actual result:
   cnt=0

Same result calling php:function('getNodesOne') or 
php:function('getNodesTwo').
In both case, the xsl variable $nodes contains a string, not an actual 
node-set that can be iterated and otherwise worked with.  
$nodes/RESULT, like $nodes/RESULT/NODE, doesn't exist.



I also tried this, but it returns an empty node-set and not even a string:
-
xsl:copy-of select=document(php:function('getNodes')) /
-


Finally, I've also tried this, but libxml2 evidently does not support the 
inline-data URI form:

-
xsl:variable name=tmp
   xsl:value-of select=php:function('getNodes') /
/xsl:variable
xsl:variable name=nodes
   xsl:copy-of select=document(concat('data:text/xml,',$tmp)) /
/xsl:variable
-

So, in all cases/combos of the above code, I get a string or an empty 
node-set.


Clearly, there should be a way to get a node-set via php:function, without 
creating a temporary xml file and without making a full request to apache.


Am I missing something?  Is something broken or, worse, broken by design?

Any help would be greatly appreciated.
thanks

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



Re: [PHP] Return Path

2005-08-06 Thread Sebastian

try using -f

mail($toemail, $subject, $message, $from, '-f [EMAIL PROTECTED]');

[EMAIL PROTECTED] wrote:

I don't seem to be able to set the return path using the mail() function. I can't figure out why from will let me set it, but not the return path. 


$headers = 'From: [EMAIL PROTECTED]' . \r\n .
  'Return-path: [EMAIL PROTECTED]' . \r\n .
  'X-Mailer: PHP/' . phpversion();

mail($email, $subject, $message, $headers);


Any thoughts?

Andrew Darrow
Kronos1 Productions
www.pudlz.com


 




--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.1/64 - Release Date: 8/4/2005

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



Re: [PHP] Return Path [SOLVED]

2005-08-06 Thread sub
Works great. Thank you.

Although I swear I tried that last night. Eh I probably messed something up.

Andrew Darrow
Kronos1 Productions
www.pudlz.com


- Original Message - 
From: Sebastian [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Saturday, August 06, 2005 6:12 AM
Subject: Re: [PHP] Return Path


 try using -f

 mail($toemail, $subject, $message, $from, '-f [EMAIL PROTECTED]');

 [EMAIL PROTECTED] wrote:

 I don't seem to be able to set the return path using the mail()
function. I can't figure out why from will let me set it, but not the
return path.
 
 $headers = 'From: [EMAIL PROTECTED]' . \r\n .
'Return-path: [EMAIL PROTECTED]' . \r\n .
'X-Mailer: PHP/' . phpversion();
 
 mail($email, $subject, $message, $headers);
 
 
 Any thoughts?
 
 Andrew Darrow
 Kronos1 Productions
 www.pudlz.com
 
 
 
 


 -- 
 No virus found in this outgoing message.
 Checked by AVG Anti-Virus.
 Version: 7.0.338 / Virus Database: 267.10.1/64 - Release Date: 8/4/2005

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





 -- 
 No virus found in this incoming message.
 Checked by AVG Anti-Virus.
 Version: 7.0.338 / Virus Database: 267.10.1/64 - Release Date: 8/4/2005



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



[PHP] Return Path

2005-08-05 Thread sub
I don't seem to be able to set the return path using the mail() function. I 
can't figure out why from will let me set it, but not the return path. 

$headers = 'From: [EMAIL PROTECTED]' . \r\n .
   'Return-path: [EMAIL PROTECTED]' . \r\n .
   'X-Mailer: PHP/' . phpversion();

mail($email, $subject, $message, $headers);


Any thoughts?

Andrew Darrow
Kronos1 Productions
www.pudlz.com



[PHP] Return value in Combo Box

2004-11-30 Thread Ahmed Abdel-Aliem
Hi, 
i have a form which user have to fill all the fields in it, when the
form is submitted it goes to a validation page which checks if users
entered all the required fields.

what i want to do is to make the validation page redirect to the form
again with the previuosly entered values, so the user can fill the
missing fields.

i can do this easily with input texts and text areas, but i don't know
how to do it with select and combo boxes.

can anyone please tell me how to make the choice the user selected in
the combo box be selected when the validation page redirects to the
form again ?

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



Re: [PHP] Return value in Combo Box

2004-11-30 Thread David Dickson
Ahmed Abdel-Aliem wrote:
Hi, 
i have a form which user have to fill all the fields in it, when the
form is submitted it goes to a validation page which checks if users
entered all the required fields.

what i want to do is to make the validation page redirect to the form
again with the previuosly entered values, so the user can fill the
missing fields.
i can do this easily with input texts and text areas, but i don't know
how to do it with select and combo boxes.
can anyone please tell me how to make the choice the user selected in
the combo box be selected when the validation page redirects to the
form again ?
What I find usually happens with selects is that I am selecting the 
option value and the display value from a table and displaying them in a 
loop, in this loop you can check if the post value is the same as the 
option value, and make it selected if it is. For example:

?php
$People = pg_exec($DBConnection, 'SELECT id, first, last FROM people');
$NumPeople = pg_numrows($People);
echo 'select name=Person';
for($i = 0; $i  $NumPeople; $i++){
$ID = pg_result($People, $i, 0);
$First = pg_result($People, $i, 1);
$Last = pg_result($People, $i, 2);
echo 'option value=' . $ID . '';
if($_POST['Person'] == $ID){ echo ' selected=selected'; }
echo '' . $First . ' ' . $Last . '/option';
}
echo '/select';
?
The key part here is the
if($_POST['Person'] == $ID){ echo ' selected=selected'; }
which will make the previously selected option selected again when the 
form is redisplayed. This also works for checkboxes, but I think 
checkboxes need checked=checked.

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


[PHP] return string size in bytes

2004-06-12 Thread PHP4web
I now there are function to calc file size but I want function to get string size in 
bytes

Re: [PHP] Return value efficiency question

2004-03-10 Thread trlists
On 10 Mar 2004 Robert Cummings wrote:

 Overhead is minimal since PHP doesn't actually copy the contents of the
 container until an attempt to modify it is made. At which time the
 contents are only actually copied if the internal reference count is
 greater than 0. Generally this means it won't be copied since your
 returning function will no longer be referencing it. This is not to be
 confused with references as programmers work with them in scripts
 themselves.

Rob I have a related question, if you know ... what is the point at 
which passing objects by reference instead of by value provides a 
performance benefit?

It sounds from the above like if you are not modifying the object in 
the called code then passing by value is always best because this is 
treated as a pass by reference unless and until there is a 
modification, so there is no performance cost.  (I udnerstand that if 
modifying it then it must be passed by reference.)

If that's right, then ...

- does the same apply to arrays? 

- what happens if you pass an object by value and then call one of
its methods which does not modify any data?  Does the object get
copied? 

Thanks for any insights ...

--
Tom




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



Re: [PHP] Return value efficiency question

2004-03-10 Thread Burhan Khalid
Kelly Hallman wrote:
Consider this method:

function xyz() {
return $this-data = unserialize($this-serial); }
Maybe I'm just being stupid, but wouldn't that simply return true if the 
assignment was successful, and false otherwise?

[ trimmed ]

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


RE: [PHP] Return value efficiency question

2004-03-10 Thread Ford, Mike [LSS]
On 10 March 2004 13:48, Burhan Khalid wrote:

 Kelly Hallman wrote:
  Consider this method:
  
  function xyz() {
  return $this-data = unserialize($this-serial); }
  
 
 Maybe I'm just being stupid, but wouldn't that simply return true if
 the assignment was successful, and false otherwise?

Nope.  The value of an assignment expression is the value assigned, so that
will return whatever was assigned into $this-data.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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



Re: [PHP] Return value efficiency question

2004-03-10 Thread messju mohr
On Wed, Mar 10, 2004 at 04:48:06PM +0300, Burhan Khalid wrote:
 Kelly Hallman wrote:
 Consider this method:
 
 function xyz() {
 return $this-data = unserialize($this-serial); }
 
 
 Maybe I'm just being stupid, but wouldn't that simply return true if the 
 assignment was successful, and false otherwise?

no, the return-value of the assignment is the right side of the
assignment (the value that was assigned).
 
 [ trimmed ]
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

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



Re: [PHP] Return value efficiency question

2004-03-10 Thread Robert Cummings
On Wed, 2004-03-10 at 08:30, [EMAIL PROTECTED] wrote:
 On 10 Mar 2004 Robert Cummings wrote:
 
  Overhead is minimal since PHP doesn't actually copy the contents of the
  container until an attempt to modify it is made. At which time the
  contents are only actually copied if the internal reference count is
  greater than 0. Generally this means it won't be copied since your
  returning function will no longer be referencing it. This is not to be
  confused with references as programmers work with them in scripts
  themselves.
 
 Rob I have a related question, if you know ... what is the point at 
 which passing objects by reference instead of by value provides a 
 performance benefit?

Passing by reference appears to provide a small amount of speed increase
though IMHO very small. Check the following three scripts:

?

$initial = array();

for( $i = 0; $i  10; $i++ )
{
$initial[$i] = $i;
}
 
for( $i = 0; $i  1000; $i++ )
{
$foo = $initial;
}

linux time command: 7.46user 0.02system 0:07.58elapsed 98%CPU


?

for( $i = 0; $i  10; $i++ )
{
$initial = $i;  
}
 
for( $i = 0; $i  1000; $i++ )
{
$foo = $initial;
}

linux time command: 7.25user 0.00system 0:07.25elapsed 99%CPU


?

$initial = array();

for( $i = 0; $i  10; $i++ )
{
$initial[$i] = $i;
}
 
for( $i = 0; $i  1000; $i++ )
{
$foo = $initial;
}

linux time command: 6.85user 0.02system 0:06.87elapsed 99%CPU


As you can see copying by value regardless of the value is pretty much
the same (I think the time discrepency is due to a slightly longer time
to populate the $initial array than to assign an integer value 10
times to $initial (which makes sense O( lg n ) versus O( 1 )).

It seems passing by reference provides a small amount of advantage
(about 5% as shown above). Even though references may be faster I would
say now that it depends on what you want to do and who is maintaining
the code :) Also copies are definitely a good choice when you are
passing data that shouldn't affect some centralized storage variable
(such is usually the case for Singleton factories). Also don't forget
that the above example is assigning the data 10 million times, generally
the difference would be almost negligible.

 It sounds from the above like if you are not modifying the object in 
 the called code then passing by value is always best because this is 
 treated as a pass by reference unless and until there is a 
 modification, so there is no performance cost.  (I udnerstand that if 
 modifying it then it must be passed by reference.)

Passing references everywhere when a reference isn't needed can make
your code more difficult to read since others reading it will constantly
be asking, is this being passed as a reference for a reason? Does
changing the value outside of the function returning it or receiving it
have some transient effect?.

 
 If that's right, then ...
 
 - does the same apply to arrays? 

Yes as shown above.

 - what happens if you pass an object by value and then call one of
 its methods which does not modify any data?  Does the object get
 copied? 

I checked with the internals list for this answer since I thought it
would work the same, and indeed it turns out that objects in PHP 4 do
work this way. However this is not quite true with PHP 5 which uses the
concept of object-handles. Nonetheless, Derick Rethans informed had the
following to say:

in php 5 it is true for object-handles and not objects, but
 that shouldn't be of any concern.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Return value efficiency question

2004-03-09 Thread Kelly Hallman
Consider this method:

function xyz() {
return $this-data = unserialize($this-serial); }

A few assumptions:
- Resultant data large enough to warrant discussion of efficiency
- I always want to store the unserialized data into the object
- The return value is only needed sometimes

If I only need to grab the return value on occassion, what is the 
overhead of returning the value, if it's discarded most of the time?

Example:
$obj-xyz(); // method returns data, but nothing is done with it

Same difference?
Or better to break this out and only use return when needed?

Appreciate any expert responses. I don't know enough about the internals 
of PHP to know the implications of this... thank you!

--Kelly

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



Re: [PHP] Return value efficiency question

2004-03-09 Thread Robert Cummings
On Wed, 2004-03-10 at 02:07, Kelly Hallman wrote:
 Consider this method:
 
 function xyz() {
 return $this-data = unserialize($this-serial); }
 
 A few assumptions:
 - Resultant data large enough to warrant discussion of efficiency
 - I always want to store the unserialized data into the object
 - The return value is only needed sometimes
 
 If I only need to grab the return value on occassion, what is the 
 overhead of returning the value, if it's discarded most of the time?
 
 Example:
 $obj-xyz(); // method returns data, but nothing is done with it
 
 Same difference?
 Or better to break this out and only use return when needed?
 
 Appreciate any expert responses. I don't know enough about the internals 
 of PHP to know the implications of this... thank you!

Overhead is minimal since PHP doesn't actually copy the contents of the
container until an attempt to modify it is made. At which time the
contents are only actually copied if the internal reference count is
greater than 0. Generally this means it won't be copied since your
returning function will no longer be referencing it. This is not to be
confused with references as programmers work with them in scripts
themselves.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Return-Path header and sending email with php

2004-01-26 Thread Marek Kilimajer
You can use a class that sends mails by connecting directly to smtp 
server, e.g. http://www.phpclasses.org/mimemessage

Chris Balay wrote:
Good Day Coders -

I have built a newsletter program with php. It sends out an e-mail to a 
couple thousand subcribers every day. All works well. My problem is that 
I have know way of finding out which e-mails are not being delivered 
successfully.

My code is as follows:

$to = stripslashes($row3[email_address]);
   
$subject = stripslashes($row3[name]).'s Curmudgeon-Online for 
.date(F j, Y);
   
$message = stripslashes($row3[name]).'s Curmudgeon-Online daily 
e-mail for .date(F j, Y).

--

.$quotes;
   
$headers = From: The Curmudgeon-Online 
[EMAIL PROTECTED]\r\n;
$headers .= Return-Path: [EMAIL PROTECTED];
$headers .= Reply-To: [EMAIL PROTECTED]\r\n;

mail($to, $subject, $message, $headers);

This generated the following headers:

Return-Path: [EMAIL PROTECTED]
Received: from [127.0.0.1] (HELO ftp.pezcandyinc.com)
  by whiteplume.net (CommuniGate Pro SMTP 4.1.5)
  with ESMTP id 1692872 for [EMAIL PROTECTED]; Sun, 25 Jan 2004 
04:03:25 -0500
Received: by ftp.pezcandyinc.com (8.12.9/8.12.9/Submit) id i0P93PqY017724;
Sun, 25 Jan 2004 04:03:25 -0500 (EST)
Date: Sun, 25 Jan 2004 04:03:25 -0500 (EST)
Message-Id: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Chris Balay's Curmudgeon-Online for January 25, 2004
From: The Curmudgeon-Online [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]

as a result any undeliverd messages are routed to 
[EMAIL PROTECTED], an address that does not exists.

Is there any way to change the return-path header?
Yours,
Chris Balay

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


[PHP] Return-Path header and sending email with php

2004-01-25 Thread Chris Balay
Good Day Coders -

I have built a newsletter program with php. It sends out an e-mail to a couple 
thousand subcribers every day. All works well. My problem is that I have know 
way of finding out which e-mails are not being delivered successfully.

My code is as follows:

$to = stripslashes($row3[email_address]);
			
$subject = stripslashes($row3[name]).'s Curmudgeon-Online for .date(F j, 
Y);
			
$message = stripslashes($row3[name]).'s Curmudgeon-Online daily e-mail for 
.date(F j, Y).

--

.$quotes;

$headers = From: The Curmudgeon-Online [EMAIL PROTECTED]\r\n;
$headers .= Return-Path: [EMAIL PROTECTED];
$headers .= Reply-To: [EMAIL PROTECTED]\r\n;

mail($to, $subject, $message, $headers);
This generated the following headers:

Return-Path: [EMAIL PROTECTED]
Received: from [127.0.0.1] (HELO ftp.pezcandyinc.com)
  by whiteplume.net (CommuniGate Pro SMTP 4.1.5)
  with ESMTP id 1692872 for [EMAIL PROTECTED]; Sun, 25 Jan 2004 04:03:25 
-0500
Received: by ftp.pezcandyinc.com (8.12.9/8.12.9/Submit) id i0P93PqY017724;
	Sun, 25 Jan 2004 04:03:25 -0500 (EST)
Date: Sun, 25 Jan 2004 04:03:25 -0500 (EST)
Message-Id: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Chris Balay's Curmudgeon-Online for January 25, 2004
From: The Curmudgeon-Online [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]

as a result any undeliverd messages are routed to [EMAIL PROTECTED], an 
address that does not exists.

Is there any way to change the return-path header? 

Yours,

Chris Balay

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


Re: [PHP] Return-Path header and sending email with php

2004-01-25 Thread David T-G
Chris --

You have started a new thread by taking an existing message and replying
to it while merely changing the Subject: line.

That is bad, because it breaks threading.  Whenever you reply to a
message, your mail client generates a References: header that tells all
recipients to which posting(s) your posting refers.  A mail client uses
this information to build a thread tree of the postings so that it is
easy to see just how they relate to each other.

With your posting style you successfully torpedoed this useful feature;
your posting shows up within an existing thread even though it is
completely unrelated.

Always do a fresh post when you want to start a new thread.  That means
that you do not select any sort of Reply when you start your message.
You can save the list address in your address book (or equivalent) for
convenience.

...and then Chris Balay said...
% 
% Good Day Coders -

Hello!


% 
% I have built a newsletter program with php. It sends out an e-mail to a 
% couple thousand subcribers every day. All works well. My problem is that I 

Interesting.  I'm always astonished the people use php for mailing list
work instead of just using mailing list software.  But I'm glad it works.


% have know way of finding out which e-mails are not being delivered 
% successfully.

If you're running under safe mode, you're apparently stuck.  If you're
not, you need to go back and read the manual again.  It's either the
second gunman on the grassy knoll or the fifth parameter ;-)


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] Return mysql_fetch_array($result) from a function

2003-11-05 Thread David Otton
On Wed, 5 Nov 2003 14:53:15 +0800, you wrote:

I am trying to get the results of a function, which queries MySQL, back into
an array for me to order. I only want to print out certain fields (I call
the same query, but use different fields in different places).

Can someone perhaps show me how to do it (or point me in the right
direction), since I need to do this:

It depends on exactly how your data is formatted, which you don't tell us.
I'm going to assume your query returns two values, id and name, and you want
them returned as a dictionary.

Probably the simplest way is to build an array as you iterate over the
query, then return it. Something like:

function ReturnSQLResults() {



$result = array ();

$rs = $mysql_query($sql);

if ($rs == FALSE)
{
return (NULL);
}

while (($row = mysql_fetch_array ($rs)) != FALSE)
{
$result[$row['id']] = $row['name'];
}

if (sizeof ($result) == 0)
{
return (FALSE);
}

return ($result);
}

You now have a function that returns NULL on error, FALSE if no records were
found, else an array of (id = name)

If you're returning more than two values, you'll probably want your array
structure to be:

(id = array(firstname, lastname))

in which case try

$result [$row['id']] = array ($row['firstname', $row['lastname']);

if you just want a straight array-of-arrays, something like

((id, firstname, lastname), (id, firstname, lastname))

then

$result[] = array($row['id', $row['firstname', $row['lastname')

will do it.

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



Re: [PHP] Return mysql_fetch_array($result) from a function

2003-11-05 Thread Chris Shiflett
--- Terence [EMAIL PROTECTED] wrote:
 I am trying to get the results of a function, which queries MySQL, back
 into an array for me to order. I only want to print out certain fields
 (I call the same query, but use different fields in different places).
 
 This works is I print out the fields in the function itself:
 
 while($row = mysql_fetch_array($result)) {
 echo $row[id] . br;
 }

So why do you not want to use this method? Does it not do what you need?


 This however prints out an unending list of values:
[snip]
 $mysql_query = mysql_fetch_array($result);
 
 while($row = $mysql_query) {
 echo $row[id] . br;
 }

$row here is being set to a result set. You are querying MySQL (with an
empty query, something I've never tried), and until MySQL fails, this will
run forever.

You probably want to run your query once and then loop through the result
set. Mind your variable names as well, because your use of $row above adds
to the confusion.

$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

Use things like that. You can also make sure $result is not false prior to
using it, because that is indicative of a failed query.

Hope that helps.

Chris

=
My Blog
 http://shiflett.org/
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

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



[PHP] Return mysql_fetch_array($result) from a function

2003-11-04 Thread Terence
Hi All,

I am trying to get the results of a function, which queries MySQL, back into
an array for me to order. I only want to print out certain fields (I call
the same query, but use different fields in different places).

This works is I print out the fields in the function itself:

while($row = mysql_fetch_array($result)) {
echo $row[id] . br;
}

This however prints out an unending list of values:

/* This is where I think it's getting messed up, since it doesnt seem to be
able to store the query in a variable. I suspect it's something to do
recursive and multi-dimension arrays
http://www.phpbuilder.com/manual/language.types.array.php*/

$mysql_query = mysql_fetch_array($result);

while($row = $mysql_query) {
echo $row[id] . br;
}


Can someone perhaps show me how to do it (or point me in the right
direction), since I need to do this:

function ReturnSQLResults() {


$mysql_query = mysql_fetch_array($result);
return $mysql_query;
}

And then be able to just print the fields I require.

Thanks in advance!!!

Terence

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



[PHP] 'Return values' from links

2003-10-17 Thread akroeger1
First of all, Hi!
I just started getting into php a week ago, but already ran into a problem I
can't seem to solve.
The issue is this : I code 2 different websites, each has it's own mySQL-DB.
Website A has a login-section, each time you successfully log in, a key is
generated which stays only valid for a certain period of time (done via
database).
Now, I have a link from the login section on website A to a sign-up-form on
website B. This sign-up is supposed to only be accessible if you have a valid
key from website A, which qualifies you as a member.
Website B lets you fill out the form no matter what key you offer it, but
when you have finished, right before I insert the data into my DB, I want it to
check back with website A whether the key is valid or not. 

That's where I'm stuck right now. 
I have a php file in website A's directory, which, when given a key value,
will check whether it is valid or not. Is there any way I can treat this
website like a function and have it give me a return value after it has run
through ?
I tried it by putting a header from B to validate.php on A, and have that
only call the 'exit;' when a valid key is provided, but it seems to proceed
with website B's code no matter what the header to website A does.

Is there any other way or workaround that I can accomplish this ? I just
need a link to that validation page, and after the link the code should proceed
or not based on the return value from that link.

By the way, I work with php3, so I hope there's a solution for that version
;)
Thanks in advance for any help, I hope my english wasn't too bad for you to
understand what I meant.

-- 
NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien...
Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService

Jetzt kostenlos anmelden unter http://www.gmx.net

+++ GMX - die erste Adresse für Mail, Message, More! +++

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



Re: [PHP] 'Return values' from links

2003-10-17 Thread David Otton
On Fri, 17 Oct 2003 08:54:23 +0200 (MEST), you wrote:

I have a php file in website A's directory, which, when given a key value,
will check whether it is valid or not. Is there any way I can treat this
website like a function and have it give me a return value after it has run
through ?

Yes; some kind of Remote Procedure Call protocol (eg SOAP) is designed for
this. But the lightweight way would be something like:

function get_token_validity ($token)
{
$token = 'token=' . rawurlencode ($token); // armour message for sending
$host = 'www.webserverA.com';
if (($sp = fsockopen ($host, 80)) == FALSE)
{
return (NULL);
}

fputs ($sp, POST /path/to/script.php HTTP/1.0\r\n);
fputs ($sp, Host: $host\r\n);
fputs ($sp, Content-type: application/x-www-form-urlencoded\r\n);
fputs ($sp, Content-length:  . strlen ($token) . \r\n\r\n);
fputs ($sp, $token\r\n);

$result = NULL;
while (!feof ($sp)) {
$a = fgets ($sp);
if (is_numeric ($a))
{
if ($a == FALSE)
{
$result = FALSE;
} else {
$result = TRUE;
}
}
}

fclose ($sp);
return ($result);
}

Untested, but it should be pretty close. Returns TRUE on a valid result,
FALSE on invalid and NULL on error.

The paired script on www.webserverA.com should just echo(1) or echo(0) for a
good or bad result.

By the way, I work with php3, so I hope there's a solution for that version
;)

/Ah/. I have to ask... why?

I have no idea whether the above code will run on PHP 3.

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



Re: [PHP] 'Return values' from links

2003-10-17 Thread David Otton
fputs ($sp, POST /path/to/script.php HTTP/1.0\r\n);
fputs ($sp, Host: $host\r\n);

Sorry. That should be HTTP/1.1, of course.

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



Re: [PHP] Return to browser and keep running!

2003-10-16 Thread Marek Kilimajer
Now I noticed you are on windows. There is a user note in the manual 
that says that this function does not work as expected on windows:

[snip]
(by priebe at mi-corporation dot com)
Note that register_shutdown_function() does not work under Apache on 
Windows platforms.  Your shutdown function will be called, but the 
connection will not close until the processing is complete.  Zend tells 
me that this is due to a difference between Apache for *nix and Apache 
for Windows.

I'm seeing similar behavior under IIS (using php4isapi).
[/snip]
But acording to this bug http://bugs.php.net/15209 the behavior changed 
between php 4.0 and 4.1. There should be new function named 
apache_register_shutdown_function and I have a feeling I have seen it 
somewhere in the manual but it seems to be gone. :(

Manuel Vázquez Acosta wrote:
Add before the exit:
set_time_limit(0);
http://php.net/set_time_limit

Curt


You didn't get the idea. I want to be able to keep running a script
disconnected from the browser; once all the output has been sent to the
browser there's no need for the user to wait until the script finish its
execution.
set_time_limit(0); makes the scripts to run completely without the 30
seconds error; but it will keep the connection with the browser; so it does
not solve the problem though
Thanks anyway,
Manu.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


  1   2   >