Re: [PHP-DEV] substr passing null...
Nathanael D. Noblet wrote: > Hello, > I just have a question, often there are 'optional' parameters to > functions, I've always thought that most of the time I could pass null > to these if I wanted to leave one empty. This has as far as I can tell > always worked except recently I was using substr(). If I pass null to > the third param, I get nothing back. Isn't passing null the same as not > passing anything? Is this a bug? Or is my logic flawed? > > I know Ilia recently fixed a few functions that didn't ignore null parameters, but it doesn't appear that substr() was one of them. Triple check the problem reproduces with the latest snapshot (snaps.php.net). If it's still broken then log a bug (bugs.php.net). Chris -- Email: christopher.jo...@oracle.com Tel: +1 650 506 8630 Twitter: http://twitter.com/ghrdFree PHP Book: http://tinyurl.com/UGPOM -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
Hi, On Mon, 2009-01-26 at 17:05 -0800, Christopher Jones wrote: > > Nathanael D. Noblet wrote: > > Hello, > > I just have a question, often there are 'optional' parameters to > > functions, I've always thought that most of the time I could pass null > > to these if I wanted to leave one empty. This has as far as I can tell > > always worked except recently I was using substr(). If I pass null to > > the third param, I get nothing back. Isn't passing null the same as not > > passing anything? Is this a bug? Or is my logic flawed? > > > > > > I know Ilia recently fixed a few functions that didn't ignore null > parameters, but it doesn't appear that substr() was one of them. I guess that's part of the zend_parse_parameters changes. As we now use the "s" modifier for instance which might better be a "s!". We should certainly spent some time on checking these things. All remember: We're feature freezing, so spend time on finding and fixing bugs instead of adding new ones! :-) (this includes users who can at least report such issues ... ) johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
Johannes Schlüter wrote: I know Ilia recently fixed a few functions that didn't ignore null parameters, but it doesn't appear that substr() was one of them. I guess that's part of the zend_parse_parameters changes. As we now use the "s" modifier for instance which might better be a "s!". We should certainly spent some time on checking these things. All remember: We're feature freezing, so spend time on finding and fixing bugs instead of adding new ones! :-) (this includes users who can at least report such issues ... ) So this morning I downloaded php5.2-200901271530, php5.3-200901271530, compiled with ./configure --prefix=/home/gnat/php5.{2,3} respectively and then used the following source file to see how they behaved. test.php: in both cases the output I get is STRING: The String is here SUB END showing that passing null as the third param for substr is somehow interpreted to mean no length or something. Is this indeed a bug then? and if so where can I submit it? -- Nathanael d. Noblet Gnat Solutions, Inc T: 403.875.4613 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
On 27.01.2009 17:36, Nathanael D. Noblet wrote: Johannes Schlüter wrote: I know Ilia recently fixed a few functions that didn't ignore null parameters, but it doesn't appear that substr() was one of them. I guess that's part of the zend_parse_parameters changes. As we now use the "s" modifier for instance which might better be a "s!". We should certainly spent some time on checking these things. All remember: We're feature freezing, so spend time on finding and fixing bugs instead of adding new ones! :-) (this includes users who can at least report such issues ... ) So this morning I downloaded php5.2-200901271530, php5.3-200901271530, compiled with ./configure --prefix=/home/gnat/php5.{2,3} respectively and then used the following source file to see how they behaved. test.php: in both cases the output I get is STRING: The String is here SUB END showing that passing null as the third param for substr is somehow interpreted to mean no length or something. Is this indeed a bug then? and if so where can I submit it? it's only a bug if you always expect optional NULL parameters to be ignored. substr() expects an int as the 3rd parameter (int) null => 0 substr($string, $start, null) => substr($string, $start, 0) = > "" (empty_string) HTH -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
Peter Walther wrote: > it's only a bug if you always expect optional NULL parameters to be ignored. Well that's the question I'm asking. I assumed optional parameters passed null should be ignored. If this isn't the behaviour php uses, then I'm good, but I've used passing null to optional params all over the place, and just recently had this one not work. If my logic / assumptions are flawed, that's fine otherwise I can file a bug. -- Nathanael d. Noblet Gnat Solutions, Inc T: 403.875.4613 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
Nathanael D. Noblet wrote: > Peter Walther wrote: > > it's only a bug if you always expect optional NULL parameters to be >> ignored. > > Well that's the question I'm asking. I assumed optional parameters > passed null should be ignored. If this isn't the behaviour php uses, > then I'm good, but I've used passing null to optional params all over > the place, and just recently had this one not work. If my logic / > assumptions are flawed, that's fine otherwise I can file a bug. > You're assumption is wrong then, NULL isn't treated as not passing a value. The reason it worked with substr was by pure chance. Scott -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
> > You're assumption is wrong then, NULL isn't treated as not passing a > value. The reason it worked with substr was by pure chance. > Out of interest, is there a reason that that is the case? Surely passing null would be best treated as the same as passing nothing?
Re: [PHP-DEV] substr passing null...
On Wed, Jan 28, 2009 at 6:39 PM, Dan wrote: >> >> You're assumption is wrong then, NULL isn't treated as not passing a >> value. The reason it worked with substr was by pure chance. >> > > Out of interest, is there a reason that that is the case? Surely passing > null would be best treated as the same as passing nothing? NULL is a value. There is no way to tell that when you pass NULL, you actually intended to pass nothing and use the default value. Paul -- Paul Biggar paul.big...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
Why don't make the function return FALSE if parameter equals NULL ? -- (c) Kenan Sulayman Freelance Designer and Programmer Life's Live Poetry 2009/1/28 Paul Biggar > On Wed, Jan 28, 2009 at 6:39 PM, Dan wrote: > >> > >> You're assumption is wrong then, NULL isn't treated as not passing a > >> value. The reason it worked with substr was by pure chance. > >> > > > > Out of interest, is there a reason that that is the case? Surely passing > > null would be best treated as the same as passing nothing? > > NULL is a value. There is no way to tell that when you pass NULL, you > actually intended to pass nothing and use the default value. > > Paul > > > -- > Paul Biggar > paul.big...@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP-DEV] substr passing null...
Hello 2009/1/28 Kenan R Sulayman : > Why don't make the function return FALSE if parameter equals NULL ? Well the $start parameter is required for substr(), so I don't see the deal here? But with now initalizers being added in the manual by Jakub its not much of a deal to use those values if you wanna use the default anyway. For example mysql_connect: http://www.php.net/mysql_connect But I do agree that in the end it would be easier to just be able to pass NULL, but it can just have a different meaning ;) > > -- > (c) Kenan Sulayman > Freelance Designer and Programmer > > Life's Live Poetry > > > 2009/1/28 Paul Biggar > >> On Wed, Jan 28, 2009 at 6:39 PM, Dan wrote: >> >> >> >> You're assumption is wrong then, NULL isn't treated as not passing a >> >> value. The reason it worked with substr was by pure chance. >> >> >> > >> > Out of interest, is there a reason that that is the case? Surely passing >> > null would be best treated as the same as passing nothing? >> >> NULL is a value. There is no way to tell that when you pass NULL, you >> actually intended to pass nothing and use the default value. >> >> Paul >> >> >> -- >> Paul Biggar >> paul.big...@gmail.com >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > -- Kalle Sommer Nielsen -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
Am 28.01.2009 um 18:41 schrieb Scott MacVicar: Nathanael D. Noblet wrote: Peter Walther wrote: it's only a bug if you always expect optional NULL parameters to be ignored. Well that's the question I'm asking. I assumed optional parameters passed null should be ignored. If this isn't the behaviour php uses, then I'm good, but I've used passing null to optional params all over the place, and just recently had this one not work. If my logic / assumptions are flawed, that's fine otherwise I can file a bug. You're assumption is wrong then, NULL isn't treated as not passing a value. The reason it worked with substr was by pure chance. Out of curiosity - how hard would it be to implement a "default" keyword that can be passed in function/method calls with the new parameter parsing API? - David smime.p7s Description: S/MIME cryptographic signature
Re: [PHP-DEV] substr passing null...
Hi, On Thu, 2009-01-29 at 09:29 +0100, David Zülke wrote: > Out of curiosity - how hard would it be to implement a "default" > keyword that can be passed in function/method calls with the new > parameter parsing API? It would mean to introduce a new value type or tons of rewrites. But as I said there's all we need with "s!" as modifier then we can handle NULL-Params independently from a String-Parameter - where this makes sense. With other functions not NULL is the default but the value of some Flag-Parameter (const DEFAULT_VALUE = 1024; function foo($param = DEFAULT_VALUE);) so this is a case by case thing ... But as said before: We should check functions where we changed the parameter parsing to be as less BC as it makes sense. johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] substr passing null...
On 27.01.2009, at 17:36, Nathanael D. Noblet wrote: showing that passing null as the third param for substr is somehow interpreted to mean no length or something. Is this indeed a bug then? and if so where can I submit it? Please submit a documentation bug if this change is not yet covered in the documentation. If you are very motivated to help us in finding and documenting such issues, I also welcome you to register on the wiki for an account so that you can work on: http://wiki.php.net/doc/scratchpad/upgrade/53 You might also want to contact php...@lists.php.net in that case. regards, Lukas Kahwe Smith m...@pooteeweet.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php