[PHP-DEV] How expensive are function_exists() calls?
I am trying to figure out a strategy for multiple output formats on a site, and it seems like I can have functions defined by default, but have them defined -after- I've included the targetted format first. However that would require file1.php: function foo() {} file2.php if(!function_exists('foo')) { function foo() {} } Is this a very expensive thing to do? There would be a good number of functions that would be leveraging this. Is it a no-no? or is it pretty cheap? Thanks - mike -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Are there plans to allow anonymous functions as callbacks?
Hi. Quite a simple question (assuming I've got the terminology correct). Are there any plans to allow code like this (amended example taken from the array_map() documentation) ... ?php $a = array(1, 2, 3, 4, 5); $b = array_map(function($n){return($n * $n * $n)}, $a); print_r($b); For me, this is cleaner than having a use-once, namespace-polluting function. Currently, this is producing a parse error. A real alternative though would be to allow nested functions... ?php function cube_array($a) { function cube($n) { return($n * $n * $n); } return array_map(cube, $a); } $a = array(1, 2, 3, 4, 5); $b = cube_array($a); print_r($b); Ideally, cube() would not be visible outside of cube_array(). Scoped functions. Regards, Richard Quadling. -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Are there plans to allow anonymous functions as callbacks?
Alexey Zakhlestin a écrit : On Wed, Mar 4, 2009 at 2:33 PM, Richard Quadling rquadl...@googlemail.com wrote: Hi. Quite a simple question (assuming I've got the terminology correct). Are there any plans to allow code like this (amended example taken from the array_map() documentation) ... ?php $a = array(1, 2, 3, 4, 5); $b = array_map(function($n){return($n * $n * $n)}, $a); print_r($b); For me, this is cleaner than having a use-once, namespace-polluting function. Currently, this is producing a parse error. It works. You have a typo. You need to put ; after return (…) Hi, with PHP 5.3, you can also use create_function() (http://www.php.net/create_function ) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Are there plans to allow anonymous functions as callbacks?
2009/3/4 Olivier B. php-dev.l...@daevel.net: Alexey Zakhlestin a écrit : On Wed, Mar 4, 2009 at 2:33 PM, Richard Quadling rquadl...@googlemail.com wrote: Hi. Quite a simple question (assuming I've got the terminology correct). Are there any plans to allow code like this (amended example taken from the array_map() documentation) ... ?php $a = array(1, 2, 3, 4, 5); $b = array_map(function($n){return($n * $n * $n)}, $a); print_r($b); For me, this is cleaner than having a use-once, namespace-polluting function. Currently, this is producing a parse error. It works. You have a typo. You need to put ; after return (…) Just shoot me now! Hi, with PHP 5.3, you can also use create_function() (http://www.php.net/create_function ) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] How expensive are function_exists() calls?
Hello Mike! Depending on how you'd define expensive, it may variate. Normally, on websites function_exists(x) ain't expensive. Altrought function_exists needed 0.77009201049805 seconds to execute. Do you think, that's pretty expensive ? Your, -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/3/4 mike mike...@gmail.com I am trying to figure out a strategy for multiple output formats on a site, and it seems like I can have functions defined by default, but have them defined -after- I've included the targetted format first. However that would require file1.php: function foo() {} file2.php if(!function_exists('foo')) { function foo() {} } Is this a very expensive thing to do? There would be a good number of functions that would be leveraging this. Is it a no-no? or is it pretty cheap? Thanks - mike -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] How expensive are function_exists() calls?
On Wed, Mar 4, 2009 at 1:07 PM, Kenan Sulayman kur...@kkooporation.dewrote: Hello Mike! Depending on how you'd define expensive, it may variate. Normally, on websites function_exists(x) ain't expensive. Altrought function_exists needed 0.77009201049805 seconds to execute. Do you think, that's pretty expensive ? Please move this thread to the php-general mailing-list. -- Mikko Koppanen
Re: [PHP-DEV] How expensive are function_exists() calls?
Update: Reached: Average: 1.3338460335041E-5 seconds / 817542. Shape: Average: ( $seconds ) seconds / ( $iterations ). -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/3/4 Kenan Sulayman kur...@kkooporation.de Hello Mike! Depending on how you'd define expensive, it may variate. Normally, on websites function_exists(x) ain't expensive. Altrought function_exists needed 0.77009201049805 seconds to execute. Do you think, that's pretty expensive ? Your, -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/3/4 mike mike...@gmail.com I am trying to figure out a strategy for multiple output formats on a site, and it seems like I can have functions defined by default, but have them defined -after- I've included the targetted format first. However that would require file1.php: function foo() {} file2.php if(!function_exists('foo')) { function foo() {} } Is this a very expensive thing to do? There would be a good number of functions that would be leveraging this. Is it a no-no? or is it pretty cheap? Thanks - mike -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Really random ?
Hello PHP internals, I've been running several million tests regarding the arithmetically-random-functions. The returning value at the end: Avg: mt_r: 1073848211.4106 r: 16384.155746685 ~8016909 Avg: mt_r: 1073904131.0286 r: 16384.164383921 ~8503575 Avg: mt_r: 1074010520.4456 r: 16384.091213092 ~13136327 Shape: Avg: mt_r: { avg of mt_rand() } r: { avg of rand() } ~ { value of $i ( iterations ) } Means: Average of mersenne twister in 8016909 it's is 1073848211.4106 ( corresponding to that in 8503575 it's the avg. is 1073904131.0286). That's acceptable. The rand(x) function alters the avg in 5M iterations really by just 0.1 ? Wow, that's creepy. Is there any way - to make it better ( or a bit as good as the m_twister is ? ) ? Thanks, -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry
Re: [PHP-DEV] Really random ?
hi, On Wed, Mar 4, 2009 at 2:50 PM, Kenan Sulayman kur...@kkooporation.de wrote: I've been running several million tests regarding the arithmetically-random-functions. The returning value at the end: Avg: mt_r: 1073848211.4106 r: 16384.155746685 ~8016909 Avg: mt_r: 1073904131.0286 r: 16384.164383921 ~8503575 Avg: mt_r: 1074010520.4456 r: 16384.091213092 ~13136327 Shape: Avg: mt_r: { avg of mt_rand() } r: { avg of rand() } ~ { value of $i ( iterations ) } Means: Average of mersenne twister in 8016909 it's is 1073848211.4106 ( corresponding to that in 8503575 it's the avg. is 1073904131.0286). That's acceptable. The rand(x) function alters the avg in 5M iterations really by just 0.1 ? Wow, that's creepy. Is there any way - to make it better ( or a bit as good as the m_twister is ? ) ? Use http://us.php.net/mtrand Still some issues but already better. Cheers, -- Pierre http://blog.thepimp.net | http://www.libgd.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Really random ?
hi, And please disable this auto reply on your system: Der Server hat ihre Nachricht erfolgreich verarbeitet! Vielen Dank, Ihr KurealCorporation Kunden Service. Cheers, -- Pierre http://blog.thepimp.net | http://www.libgd.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Really random ?
Hey Pierre! Didn't I included the mt_rand function in my tests ? Quote: Average of mersenne twister in 8016909 it's is 1073848211.4106 ( corresponding to that in 8503575 it's the avg. is 1073904131.0286). The mail was meant to make the rand(x) function more good; I already use the mt_rand() function, but why should the rand(x) function still be used, if it's so freakin' insecure ? P.s.: Thanks for the And please disable this auto reply on your system:; I thought, I disabled that a year ago ;-P. Your, -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/3/4 Pierre Joye pierre@gmail.com hi, And please disable this auto reply on your system: Der Server hat ihre Nachricht erfolgreich verarbeitet! Vielen Dank, Ihr KurealCorporation Kunden Service. Cheers, -- Pierre http://blog.thepimp.net | http://www.libgd.org
Re: [PHP-DEV] Really random ?
Kenan Sulayman wrote: The rand(x) function alters the avg in 5M iterations really by just 0.1 ? Wow, that's creepy. Is there any way - to make it better ( or a bit as good as the m_twister is ? ) ? there's a reason why mt_rand() is referred to as Generate a better random value in the rand() documentation ;) And i can't resist to add http://web.archive.org/web/20011027002011/http://dilbert.com/comics/dilbert/archive/images/dilbert2001182781025.gif -- Hartmut Holzgraefe, MySQL Regional Support Manager, EMEA Sun Microsystems GmbH, Sonnenallee 1, 85551 Kirchheim-Heimstetten Amtsgericht Muenchen: HRB161028 Geschaeftsfuehrer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer Vorsitzender des Aufsichtsrates: Martin Haering -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Really random ?
On 4 Mar 2009, at 15:46, Kenan Sulayman wrote: Hey Pierre! Didn't I included the mt_rand function in my tests ? Quote: Average of mersenne twister in 8016909 it's is 1073848211.4106 ( corresponding to that in 8503575 it's the avg. is 1073904131.0286). The mail was meant to make the rand(x) function more good; I already use the mt_rand() function, but why should the rand(x) function still be used, if it's so freakin' insecure ? I hope that by insecure you don't imply that you're using those pseudorandom generators for cryptography purposes. As the manual states, rand() uses the libc rand(), which can be desirable if you want to generate the same sequence of numbers across languages. And you don't need to complain about its drawbacks, because they are well- known (see http://en.wikipedia.org/wiki/Linear_congruential_generator#Advantages_and_disadvantages_of_LCGs ). If you want secure random numbers, use something that at least tries to utilize real entropy. But that topic has nothing to do with the development of PHP ... Regards, Stefan -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Should windows builds of PHP have the https protocol registered?
Hi. Running PHP Version 5.3.0beta2-dev on Windows Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar As such, I can't use https. Except for curl. Is that normal? -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Really random ?
Guess you're right ;-D Thanks! -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/3/4 Stefan Walk e...@php.net On 4 Mar 2009, at 15:46, Kenan Sulayman wrote: Hey Pierre! Didn't I included the mt_rand function in my tests ? Quote: Average of mersenne twister in 8016909 it's is 1073848211.4106 ( corresponding to that in 8503575 it's the avg. is 1073904131.0286). The mail was meant to make the rand(x) function more good; I already use the mt_rand() function, but why should the rand(x) function still be used, if it's so freakin' insecure ? I hope that by insecure you don't imply that you're using those pseudorandom generators for cryptography purposes. As the manual states, rand() uses the libc rand(), which can be desirable if you want to generate the same sequence of numbers across languages. And you don't need to complain about its drawbacks, because they are well-known (see http://en.wikipedia.org/wiki/Linear_congruential_generator#Advantages_and_disadvantages_of_LCGs). If you want secure random numbers, use something that at least tries to utilize real entropy. But that topic has nothing to do with the development of PHP ... Regards, Stefan -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Should windows builds of PHP have the https protocol registered?
hi, It is, via openssl. php -d extension_dir=ext -dextension=php_openssl.dll -r print_r(stream_get _wrappers()); Array ( [0] = php [1] = file [2] = glob [3] = data [4] = http [5] = ftp [6] = zip [7] = compress.zlib [8] = https [9] = ftps [10] = phar ) php -d extension_dir=ext -dextension=php_openssl.dll -i | find https Registered PHP Streams = php, file, glob, data, http, ftp, zip, compress.zlib, https, ftps, phar Are you sure openssl is loaded? Cheers, On Wed, Mar 4, 2009 at 4:38 PM, Richard Quadling rquadl...@googlemail.com wrote: Hi. Running PHP Version 5.3.0beta2-dev on Windows Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar As such, I can't use https. Except for curl. Is that normal? -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Pierre http://blog.thepimp.net | http://www.libgd.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Should windows builds of PHP have the https protocol registered?
2009/3/4 Pierre Joye pierre@gmail.com: hi, It is, via openssl. php -d extension_dir=ext -dextension=php_openssl.dll -r print_r(stream_get _wrappers()); Array ( [0] = php [1] = file [2] = glob [3] = data [4] = http [5] = ftp [6] = zip [7] = compress.zlib [8] = https [9] = ftps [10] = phar ) php -d extension_dir=ext -dextension=php_openssl.dll -i | find https Registered PHP Streams = php, file, glob, data, http, ftp, zip, compress.zlib, https, ftps, phar Are you sure openssl is loaded? Cheers, On Wed, Mar 4, 2009 at 4:38 PM, Richard Quadling rquadl...@googlemail.com wrote: Hi. Running PHP Version 5.3.0beta2-dev on Windows Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar As such, I can't use https. Except for curl. Is that normal? -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Pierre http://blog.thepimp.net | http://www.libgd.org !#*$$£~ -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Re: cvs: php-src(PHP_5_3) /ext/standard/tests/general_functions phpinfo.phpt
Zoe Slattery wrote: zoe Wed Mar 4 10:23:01 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/standard/tests/general_functions phpinfo.phpt Log: fixed test http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/general_functions/phpinfo.phpt?r1=1.1.2.2.2.8r2=1.1.2.2.2.9diff_format=u Index: php-src/ext/standard/tests/general_functions/phpinfo.phpt diff -u php-src/ext/standard/tests/general_functions/phpinfo.phpt:1.1.2.2.2.8 php-src/ext/standard/tests/general_functions/phpinfo.phpt:1.1.2.2.2.9 --- php-src/ext/standard/tests/general_functions/phpinfo.phpt:1.1.2.2.2.8 Sun Feb 15 21:46:01 2009 +++ php-src/ext/standard/tests/general_functions/phpinfo.phpt Wed Mar 4 10:23:01 2009 @@ -46,27 +46,17 @@ Configuration - -%a - +%A Hi Zoe, Is there documentation on this change? I'm finding it a little bit arbitrary that run-tests keeps changing basic stuff so often, it's making me split tests simply to have a different EXPECTF for php 5.2 vs. 5.3. First it was %s, then %a, and now %A to match multi-line? Thanks, Greg -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Re: cvs: php-src(PHP_5_3) /ext/standard/tests/general_functions phpinfo.phpt
Hi Zoe, Is there documentation on this change? Hi Greg - you mean the change I made to the phpinfo.phpt test? If so I changed it because it was failing and should not have been. Or do you mean changes to run-tests.php options? I'm finding it a little bit arbitrary that run-tests keeps changing basic stuff so often, it's making me split tests simply to have a different EXPECTF for php 5.2 vs. 5.3. First it was %s, then %a, and now %A to match multi-line? Sure - all the --EXPECTF-- options are documented here http://qa.php.net/expectf_details.php, and, as far as I'm aware all the EXPECTF options should be common to PHP 52, PHP 53 and PHP 6. If they aren't then it's an oversight and I'll be happy to fix. I don't think any of them should require changes to existing tests. Zoe -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Re: cvs: php-src(PHP_5_3) /ext/standard/tests/general_functions phpinfo.phpt
zoe wrote: Hi Zoe, Is there documentation on this change? Hi Greg - you mean the change I made to the phpinfo.phpt test? If so I changed it because it was failing and should not have been. Or do you mean changes to run-tests.php options? I meant to run-tests.php. I'm finding it a little bit arbitrary that run-tests keeps changing basic stuff so often, it's making me split tests simply to have a different EXPECTF for php 5.2 vs. 5.3. First it was %s, then %a, and now %A to match multi-line? Sure - all the --EXPECTF-- options are documented here http://qa.php.net/expectf_details.php, and, as far as I'm aware all the EXPECTF options should be common to PHP 52, PHP 53 and PHP 6. If they aren't then it's an oversight and I'll be happy to fix. I don't think any of them should require changes to existing tests. Thanks, this is very helpful, and answers all of my questions. Greg -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Really random ?
Kenan Sulayman wrote: Hello PHP internals, I've been running several million tests regarding the arithmetically-random-functions. The returning value at the end: Avg: mt_r: 1073848211.4106 r: 16384.155746685 ~8016909 Avg: mt_r: 1073904131.0286 r: 16384.164383921 ~8503575 Avg: mt_r: 1074010520.4456 r: 16384.091213092 ~13136327 Shape: Avg: mt_r: { avg of mt_rand() } r: { avg of rand() } ~ { value of $i ( iterations ) } Means: Average of mersenne twister in 8016909 it's is 1073848211.4106 ( corresponding to that in 8503575 it's the avg. is 1073904131.0286). That's acceptable. The rand(x) function alters the avg in 5M iterations really by just 0.1 ? Wow, that's creepy. You're exhausting the period. It's not creepy, it's expected, for a random number generator with only 16 bits of state. Is there any way - to make it better ( or a bit as good as the m_twister is ? ) ? No, apparently it's conventional to expose whatever crap PRNG the system has lying around instead of forcing programmers to use one of the two perfectly good ones that PHP bundles. -- Tim Starling -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php