Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Andrea Faulds
Hey,

 On 13 Feb 2015, at 07:28, Michael Wallner m...@php.net wrote:
 
 On 12/02/15 19:55, Thomas Punt wrote:
 
 I'd like to propose to make empty() a variadic, where if any
 arguments passed in are considered empty, then false is returned
 
 Should that read if any arguments passed in are considered *NOT* empty,
 then false is returned”?

No, I think it’s correct, if confusingly phrased. I believe Thomas is proposing 
variadic empty() where TRUE is returned if any of its arguments are empty, 
otherwise FALSE. So, empty($a, $b, $c) would be equivalent to empty($a) || 
empty($b) || empty($c), much like isset($a, $b, $c) is equivalent to (and 
implemented as) isset($a)  isset($b)  isset($c).

--
Andrea Faulds
http://ajf.me/





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Andrea Faulds

 On 13 Feb 2015, at 11:16, Andrea Faulds a...@ajf.me wrote:
 
 Hey,
 
 On 13 Feb 2015, at 07:28, Michael Wallner m...@php.net wrote:
 
 On 12/02/15 19:55, Thomas Punt wrote:
 
 I'd like to propose to make empty() a variadic, where if any
 arguments passed in are considered empty, then false is returned
 
 Should that read if any arguments passed in are considered *NOT* empty,
 then false is returned”?
 
 No, I think it’s correct, if confusingly phrased. I believe Thomas is 
 proposing variadic empty() where TRUE is returned if any of its arguments are 
 empty, otherwise FALSE. So, empty($a, $b, $c) would be equivalent to 
 empty($a) || empty($b) || empty($c), much like isset($a, $b, $c) is 
 equivalent to (and implemented as) isset($a)  isset($b)  isset($c).

Wait, I think I made a mistake.

* Thomas proposed if any arguments passed in are considered empty, then false 
is returned”, i.e. !(empty($a) || empty($b) || empty($c)) if his words are 
taken literally. This doesn’t make much sense, I think it was a mistake.
* You suggested he may have meant if any arguments passed in are considered 
*NOT* empty, then false is returned”, i.e. (empty($a)  empty($b)  empty($c))
* I assume Thomas actually meant “where if any arguments passed in are 
considered empty, then *true* is returned”, i.e. (empty($a) || empty($b) || 
empty($c))

Sorry for the confusion.

I think the || behaviour is the most useful, as it’s the analogue of isset’s. 
So !empty($a, $b, $c) would work similarly to isset($a, $b, $c), and similarly, 
!isset($a, $b, $c) would work similarly to empty($a, $b, $c).

But that’s just my opinion. :)
--
Andrea Faulds
http://ajf.me/





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread reeze
Hi,

On 13 February 2015 at 19:31, Andrea Faulds a...@ajf.me wrote:


  On 13 Feb 2015, at 11:16, Andrea Faulds a...@ajf.me wrote:
 
  Hey,
 
  On 13 Feb 2015, at 07:28, Michael Wallner m...@php.net wrote:
 
  On 12/02/15 19:55, Thomas Punt wrote:
 
  I'd like to propose to make empty() a variadic, where if any
  arguments passed in are considered empty, then false is returned
 
  Should that read if any arguments passed in are considered *NOT* empty,
  then false is returned?
 
  No, I think it's correct, if confusingly phrased. I believe Thomas is
 proposing variadic empty() where TRUE is returned if any of its arguments
 are empty, otherwise FALSE. So, empty($a, $b, $c) would be equivalent to
 empty($a) || empty($b) || empty($c), much like isset($a, $b, $c) is
 equivalent to (and implemented as) isset($a)  isset($b)  isset($c).

 Wait, I think I made a mistake.

 * Thomas proposed if any arguments passed in are considered empty, then
 false is returned, i.e. !(empty($a) || empty($b) || empty($c)) if his
 words are taken literally. This doesn't make much sense, I think it was a
 mistake.
 * You suggested he may have meant if any arguments passed in are
 considered *NOT* empty, then false is returned, i.e. (empty($a) 
 empty($b)  empty($c))
 * I assume Thomas actually meant where if any arguments passed in are
 considered empty, then *true* is returned, i.e. (empty($a) || empty($b) ||
 empty($c))

 Sorry for the confusion.

 I think the || behaviour is the most useful, as it's the analogue of
 isset's. So !empty($a, $b, $c) would work similarly to isset($a, $b, $c),
 and similarly, !isset($a, $b, $c) would work similarly to empty($a, $b, $c).


For example: echo $a, $b, $c,  empty($a, $b, $c), they are treated equal,

if the empty() means if any one of them is empty then result is TRUE, the
advantage of it disappeared:

if (empty($a, $b, $c)) {
   // you might want to check it again.
   if (empty($a)) {
  //blah blah.
   } else if (empty($b)) {

   }
}



 But that's just my opinion. :)
 --
 Andrea Faulds
 http://ajf.me/





 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Reeze Xia
http://reeze.cn


RE: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Thomas Punt
Hi,

 From: a...@ajf.me
 * I assume Thomas actually meant “where if any arguments passed in are 
 considered empty, then *true* is returned”, i.e. (empty($a) || empty($b) || 
 empty($c))
 
 Sorry for the confusion.
 
 I think the || behaviour is the most useful, as it’s the analogue of isset’s. 
 So !empty($a, $b, $c) would work similarly to isset($a, $b, $c), and 
 similarly, !isset($a, $b, $c) would work similarly to empty($a, $b, $c).
 
 But that’s just my opinion. :)
 --
 Andrea Faulds
 http://ajf.me/

Yeah, my mistake. That's what I meant - empty will return TRUE if *any* of its 
arguments are considered empty, and FALSE otherwise. So the following two 
pieces of code are analogous:
# this:if (empty($a) || empty($b) || empty($c)) {// error here}
# is the same as this:if (empty($a, $b, $c)) {// error here}
# and this:if (!empty($a)  !empty($b)  !empty($c)) {// all good!}
# is the same as this:if (!empty($a, $b, $c)) {// all good!}
Sorry for the confusion :p
-Tom  

RE: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Thomas Punt
Hi Francois,

 From: franc...@tekwire.net
 May I suggest to extend your proposal to is_null() with the same logic ?
If we were to do the same with is_null(), then would it not be best to do it 
with all the is_*() functions? I would be more than happy to cater for those 
functions as well, though their usages seem a lot less common. What does 
everyone else think?
 
 François

Thanks, Tom   

RE: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread François Laupretre
 De : Michael Wallner [mailto:mike.php@gmail.com] De la part de Michael
Wallner

  I think the || behaviour is the most useful, as it’s the analogue of
  isset’s. So !empty($a, $b, $c) would work similarly to isset($a, $b,
  $c), and similarly, !isset($a, $b, $c) would work similarly to
  empty($a, $b, $c).
 
  But that’s just my opinion. :)
 
 Okay, while I think it has a tiny WTF attached, because isset() has ALL
 semantics and empty() would have ANY semantics, it's probably useful
 only in that way.

Agreed. Adds an ambiguity but would be useless otherwise.

May I suggest to extend your proposal to is_null() with the same logic ?

François





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Sebastian B.-Hagensen
Hi,

2015-02-13 14:45 GMT+01:00 Thomas Punt tp...@hotmail.co.uk:
 Hi Francois,

 From: franc...@tekwire.net
 May I suggest to extend your proposal to is_null() with the same logic ?
 If we were to do the same with is_null(), then would it not be best to do it 
 with all the is_*() functions? I would be more than happy to cater for those 
 functions as well, though their usages seem a lot less common. What does 
 everyone else think?

While I don't know how common such a usage is I'm certain that there
is a use case for it. However, just modifying a subset of the is_*
functions sounds like a bad idea. If such a change is applied it
should be done to all type related is_* functions and be  similar to
issets behavior (return false if at least one argument is not of the
given type).

Thanks,

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Thomas Punt
Hi,

 Date: Fri, 13 Feb 2015 15:09:16 +0100
 From: sbj.ml.r...@gmail.com
 
 While I don't know how common such a usage is I'm certain that there
 is a use case for it. However, just modifying a subset of the is_*
 functions sounds like a bad idea. If such a change is applied it
 should be done to all type related is_* functions and be  similar to
 issets behavior (return false if at least one argument is not of the
 given type).
 
 Thanks,

Agreed on that. It would be better for consistency's sake.
-Tom  

Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Benoit Schildnecht

Hi,

Sebastian B.-Hagensen  a écrit dans le message de groupe de discussion : 
caojcv8yx7vohtd1ja2obdrntdzb0q1soyqdyhsar3vt2vgs...@mail.gmail.com...



2015-02-13 14:45 GMT+01:00 Thomas Punt tp...@hotmail.co.uk:

Hi Francois,


From: franc...@tekwire.net
May I suggest to extend your proposal to is_null() with the same logic ?
If we were to do the same with is_null(), then would it not be best to do 
it with all the is_*() functions? I would be more than happy to cater for 
those functions as well, though their usages seem a lot less common. What 
does everyone else think?



While I don't know how common such a usage is I'm certain that there
is a use case for it. However, just modifying a subset of the is_*
functions sounds like a bad idea. If such a change is applied it
should be done to all type related is_* functions and be  similar to
issets behavior (return false if at least one argument is not of the
given type).


I agree, this behaviour should be extended to all the is_* functions if 
possible. 



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Benoit Schildnecht

Hey Tom,

Thomas Punt  a écrit dans le message de groupe de discussion


Hey Benoit,



From: bensor...@neuf.fr
Hi,

I agree, this behaviour should be extended to all the is_* functions if
possible.



I'm not sure we can do that for all of the is_* functions, since 
is_callable() accepts up to three arguments rather than taking only a 
single argument like the rest.


Oops, I should have written when possible, that's what I meant. My bad :)

Regards,
Benoit. 



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Thomas Punt
Hi Reeze,

 From: re...@php.net
 
 For example: echo $a, $b, $c,  empty($a, $b, $c), they are treated equal,
 
 if the empty() means if any one of them is empty then result is TRUE, the
 advantage of it disappeared:
 
 if (empty($a, $b, $c)) {
 // you might want to check it again.
 if (empty($a)) {
 //blah blah.
 } else if (empty($b)) {
 
 }
 }
 


Having empty() return TRUE if *all* arguments are empty, and FALSE otherwise 
doesn't seem to be as useful (at least from what I've seen in code).


It's less common to see:

if (empty($a)  empty($b)  empty($c)) {}

than:

if (empty($a) || empty($b) || empty($c)) {}

Plus then the semantics wouldn't be inline with isset(), which could be 
somewhat confusing to users.

 
 -- 
 Reeze Xia
 http://reeze.cn

Thanks,
Tom   

Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-13 Thread Michael Wallner
On 13/02/15 12:31, Andrea Faulds wrote:
 
 On 13 Feb 2015, at 11:16, Andrea Faulds a...@ajf.me wrote:
 
 Hey,
 
 On 13 Feb 2015, at 07:28, Michael Wallner m...@php.net wrote:
 
 On 12/02/15 19:55, Thomas Punt wrote:
 
 I'd like to propose to make empty() a variadic, where if any 
 arguments passed in are considered empty, then false is
 returned
 
 Should that read if any arguments passed in are considered *NOT*
 empty, then false is returned”?
 
 No, I think it’s correct, if confusingly phrased. I believe Thomas
 is proposing variadic empty() where TRUE is returned if any of its
 arguments are empty, otherwise FALSE. So, empty($a, $b, $c) would
 be equivalent to empty($a) || empty($b) || empty($c), much like
 isset($a, $b, $c) is equivalent to (and implemented as) isset($a)
  isset($b)  isset($c).
 
 Wait, I think I made a mistake.
 
 * Thomas proposed if any arguments passed in are considered empty,
 then false is returned”, i.e. !(empty($a) || empty($b) || empty($c))
 if his words are taken literally. This doesn’t make much sense, I
 think it was a mistake.

 * You suggested he may have meant if any arguments passed in are
 considered *NOT* empty, then false is returned”, i.e. (empty($a) 
 empty($b)  empty($c))

 * I assume Thomas actually meant “where if any arguments passed in
 are considered empty, then *true* is returned”, i.e. (empty($a) ||
 empty($b) || empty($c))

 
 Sorry for the confusion.
 
 I think the || behaviour is the most useful, as it’s the analogue of
 isset’s. So !empty($a, $b, $c) would work similarly to isset($a, $b,
 $c), and similarly, !isset($a, $b, $c) would work similarly to
 empty($a, $b, $c).
 
 But that’s just my opinion. :)

Okay, while I think it has a tiny WTF attached, because isset() has ALL
semantics and empty() would have ANY semantics, it's probably useful
only in that way.



-- 
Regards,
Mike

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-12 Thread Kris Craig
On Thu, Feb 12, 2015 at 10:55 AM, Thomas Punt tp...@hotmail.co.uk wrote:

 Hello PHP Internals!
 I'd like to propose to make empty() a variadic, where if any arguments
 passed in are considered empty, then false is returned - otherwise return
 true.
 My reasoning for wanting this feature is as follows:1)It's a common
 scenario to want to check multiple expressions for empty values. I
 frequently see both of the following pieces of code in projects:#1
 if (empty($a) || empty($b) || empty($c)) {// error here}
 #2if (!empty($a)  !empty($b)  !empty($c)) {// all
 good!}
 Both of the above examples could be shortened if empty() was made to
 accept multiple arguments:#1if (empty($a, $b, $c)) {//
 error here}
 #2if (!empty($a, $b, $c)) {// all good!}
 This creates more compact code that is (in my oppinion, at least) easier
 to read.
 Some code from real-world projects that could benefit from this
 feature:WordPress (one of many):
 https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/template.php#L1963OpenCart:

 https://github.com/opencart/opencart/blob/45fc863fa068d82b5280890e6466a198faa54bff/upload/admin/controller/openbay/ebay_profile.php#L128phpbb:

 https://github.com/phpbb/phpbb/blob/040d451dcca9ae54d8f4b7bdd2f231033765a8f2/phpBB/phpbb/notification/method/jabber.php#L48

 2)Users have brought up the want to pass in multiple arguments into
 empty() before, such as:
 http://stackoverflow.com/questions/4993104/using-ifempty-with-multiple-variables-phphttp://stackoverflow.com/questions/10950470/check-if-multiple-strings-are-empty
 There have been solutions brought up by users to emulate a variadic empty,
 like [1][2], however for unset variables their solutions simply don't work.

 So all in all, it seems like a simple feature to add for a short-hand
 notation of checking multiple expressions for emptiness (which seems like a
 common use-case for users). It has no BC implications and no real downsides
 (at least I couldn't think of any). I have created a patch [3], and if the
 feedback is positive, then I'll create an RFC and submit a PR.
 Thanks,Tom
 [1] http://stackoverflow.com/a/7798842/4530326[2]
 http://icoded.it/php-time-saving-function-to-check-multiple-variables-for-empty-values/[3]
 https://github.com/tpunt/php-src/commit/66c563829775770507147872b98320cdfcb6c51c




I'd say go ahead and draft an RFC with all the details of your proposed
change, then we can discuss and vote on it.  On the surface, it looks like
a useful feature that wouldn't break any existing code.

--Kris


RE: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-12 Thread Thomas Punt
Hi Kris,

 Date: Thu, 12 Feb 2015 11:21:40 -0800
 From: kris.cr...@gmail.com
 To: tp...@hotmail.co.uk
 CC: internals@lists.php.net
 Subject: Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic
 
 I'd say go ahead and draft an RFC with all the details of your proposed
 change, then we can discuss and vote on it.  On the surface, it looks like
 a useful feature that wouldn't break any existing code.
 
 --Kris

Will do! Also, apologies for the email formatting - I didn't realise my message 
was going to be mangled when sent...  

Re: [PHP-DEV] [DISCUSSION] Make empty() a Variadic

2015-02-12 Thread Michael Wallner
On 12/02/15 19:55, Thomas Punt wrote:

 I'd like to propose to make empty() a variadic, where if any
 arguments passed in are considered empty, then false is returned

Should that read if any arguments passed in are considered *NOT* empty,
then false is returned?


-- 
Regards,
Mike

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php