Re: [PHP-DEV] Function proposal: varset

2011-04-27 Thread Mark
Any idea on how to progress with this idea?
I certainly would like to see it in PHP 5.4 but i don't have the knowledge
nor time to figure out the php internals (in C...)

On Sat, Apr 23, 2011 at 4:04 AM, Ben Schmidt
mail_ben_schm...@yahoo.com.auwrote:

 yeah you are right, passing arguments by reference doesn't trigger the
 notice, but I'm not sure that it is applicable in our case.


 Yeah, it wouldn't help. For instance, 42 or default can't be passed by
 reference, so you couldn't actually provide a default value to
 coalesce() if you implemented it like that, which would make it pretty
 useless. :-)

 Ben.






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




Re: [PHP-DEV] Function proposal: varset

2011-04-22 Thread Ben Schmidt

yeah you are right, passing arguments by reference doesn't trigger the
notice, but I'm not sure that it is applicable in our case.


Yeah, it wouldn't help. For instance, 42 or default can't be passed by
reference, so you couldn't actually provide a default value to
coalesce() if you implemented it like that, which would make it pretty
useless. :-)

Ben.





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



RE: [PHP-DEV] Function proposal: varset

2011-04-21 Thread Jonathan Bond-Caron
On Wed Apr 20 04:41 PM, D. Dante Lorenso wrote:
 
 My proposal was called filled since it was the opposite of empty
 which already existed.  I extended the function to return the first 
 non-empty value or null if all values evaluated as empty.
 
 You could use the function like this:
 
$x = filled($_GET['x'], $obj-something, $default, 'default');
 
 Like I said, though, I don't think this can be done in the language 
 because I think they ran out of OPCODES and would have to tear apart 
 the whole PHP engine to support such a feature.
 

That's not the reason, there's 127 / 256 opcodes.

So far filled, varset, coallesce, ifsetor or any operator would likely 
have to manipulate opcodes.

http://php.net/~helly/ze2-ifsetor-20040901.diff.txt

From what I understand, zeev and andi are strongly opposed to adding a new 
opcode. I'm sure they have their reasons.

Maybe there's another approach where ~ E_NONE could be passed to zend_error

ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
{
   if(type  E_NONE)
  return;
}

Then modify to zend_vm_gen.php to pass E_NONE if within 'ifsetor'.

Either way, there's a solution for it, I think the debate is over how it's 
implemented.

-- Worth reading

https://wiki.php.net/rfc/ifsetor#rejected_features

-- Why?

I think it simply boils down to this:
- PHP *developers* want a function for it.

Derick
 




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



Re: [PHP-DEV] Function proposal: varset

2011-04-21 Thread Brian Moon

I proposed something similar over 5 years ago. It ain't gonna happen
because PHP language can't support it.


It supports it. Several functions allow you to pass in variables that 
are not set and don't throw an error. Not sure what you are talking about.


Brian.

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



Re: [PHP-DEV] Function proposal: varset

2011-04-21 Thread Ferenc Kovacs
On Thu, Apr 21, 2011 at 8:37 PM, Brian Moon br...@moonspot.net wrote:

 I proposed something similar over 5 years ago. It ain't gonna happen
 because PHP language can't support it.


 It supports it. Several functions allow you to pass in variables that are
 not set and don't throw an error. Not sure what you are talking about.


?
which one?
I guess that you are talking about the language constructs like isset and
empty.
they aren't functions.

Tyrael


Re: [PHP-DEV] Function proposal: varset

2011-04-21 Thread Brian Moon

which one?
I guess that you are talking about the language constructs like isset and
empty.
they aren't functions.


settype() for one.

Brian.

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



Re: [PHP-DEV] Function proposal: varset

2011-04-21 Thread Ferenc Kovacs
On Fri, Apr 22, 2011 at 12:07 AM, Brian Moon br...@moonspot.net wrote:

 which one?
 I guess that you are talking about the language constructs like isset and
 empty.
 they aren't functions.


 settype() for one.

 Brian.


yeah you are right, passing arguments by reference doesn't trigger the
notice, but I'm not sure that it is applicable in our case.

Tyrael


Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Alain Williams
On Wed, Apr 20, 2011 at 04:55:00PM +0200, Mark wrote:
 Hi,
 
 This proposal is for the often called line like this:
 $var = isset($_GET['var']) ? $_GET['var'] : '';
 
 Only a shorter and imho a cleaner solution to get the same:
 $var = varset($_GET['var']);

It should be called var_set() - better on name space pollution.

 However there is a slight issue with this approach. If notices are turned on
 this code will generate a notice while i think it should not do that. But
 perhaps this approach is to short.
 A slightly different implementation (and longer) prevents the notice:

If is is a language element (like isset()) then you can avoid this problem.

I do find a lot of code, in simple scripts, that does just that.

It might be nice to extend it such that if the 1st argument is a list then the
first in the list which is set is returned, eg:

$var = var_set(($_GET['var'], $_POST['var']), 'default');

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h

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



Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Mark
On Wed, Apr 20, 2011 at 5:12 PM, Alain Williams a...@phcomp.co.uk wrote:

 On Wed, Apr 20, 2011 at 04:55:00PM +0200, Mark wrote:
  Hi,
 
  This proposal is for the often called line like this:
  $var = isset($_GET['var']) ? $_GET['var'] : '';
 
  Only a shorter and imho a cleaner solution to get the same:
  $var = varset($_GET['var']);

 It should be called var_set() - better on name space pollution.


oke


   However there is a slight issue with this approach. If notices are
 turned on
  this code will generate a notice while i think it should not do that. But
  perhaps this approach is to short.
  A slightly different implementation (and longer) prevents the notice:

 If is is a language element (like isset()) then you can avoid this problem.


Could you explain that a bit more?


 I do find a lot of code, in simple scripts, that does just that.

 It might be nice to extend it such that if the 1st argument is a list then
 the
 first in the list which is set is returned, eg:

$var = var_set(($_GET['var'], $_POST['var']), 'default');


I might be missing the point here, but the way i understand it that can give
unexpected results.. since it returns the first element from an array in
your suggestion but that's not what you want to do.


 --
 Alain Williams
 Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT
 Lecturer.
 +44 (0) 787 668 0256  http://www.phcomp.co.uk/
 Parliament Hill Computers Ltd. Registration Information:
 http://www.phcomp.co.uk/contact.php
 #include std_disclaimer.h



Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Alain Williams
On Wed, Apr 20, 2011 at 05:19:36PM +0200, Mark wrote:

  If is is a language element (like isset()) then you can avoid this problem.
 
 
 Could you explain that a bit more?

It looks like a function but is not:

http://uk3.php.net/manual/en/function.isset.php

  It might be nice to extend it such that if the 1st argument is a list then
  the
  first in the list which is set is returned, eg:
 
 $var = var_set(($_GET['var'], $_POST['var']), 'default');
 
 
 I might be missing the point here, but the way i understand it that can give
 unexpected results.. since it returns the first element from an array in
 your suggestion but that's not what you want to do.

I mean that it checks $_GET['var'], then $_POST['var']  returns the first of 
the two that is set
or 'default'.

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h

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



RE: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Jonathan Bond-Caron
On Wed Apr 20 10:55 AM, Mark wrote:
 
 function varset($arr, $key, $default = '') { return (isset($arr[$key]) 
 ? $arr[$key] : $default); }
 
 where the call would be:
 $var = varset($_GET, 'var');
 
 I personally like both ways...
 My proposal is to make this function a core php function in PHP 5.4.
 The added benifit is obvious. People can, with this, use a way shorter 
 notation to validate if a given array element exists. Right now that 
 needs to be done with a ternary, filter_var or some other method 
 (there are quite a few ways to check for existence).
 
 I tried to look in the PHP source to see if i could make a patch to 
 add this but i couldn't find the function that defines the isset 
 function (i wanted to base it on that). So a pointer to the right 
 location would be nice (along with docs that tell me what i all need 
 to do to implement a new php function). 

https://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_language_parser.y?rev
ision=306938view=markup

Look for isset_variables:, then zend_do_isset_or_isempty

isset() lives in the parser and requires some advanced knowledge of the
opcodes (personally I'm not there yet)

 
 So, what do you think of this?
 

I like the idea, it could also be called vardef() or var_default()



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



Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Brian Moon

It might be nice to extend it such that if the 1st argument is a list then the
first in the list which is set is returned, eg:

$var = var_set(($_GET['var'], $_POST['var']), 'default');


If that is the usage, I would suggest coalesce() to be consistent with 
the same concept in SQL. And you would not need a list as the first 
argument. Just pass multiple arguments and return the first set value.


$var = var_set($_GET['var'], $_POST['var'], 'default');

http://en.wikipedia.org/wiki/Null_%28SQL%29#COALESCE

Brian.

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



Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Alain Williams
On Wed, Apr 20, 2011 at 11:06:47AM -0500, Brian Moon wrote:
 It might be nice to extend it such that if the 1st argument is a list then 
 the
 first in the list which is set is returned, eg:
 
  $var = var_set(($_GET['var'], $_POST['var']), 'default');
 
 If that is the usage, I would suggest coalesce() to be consistent with 
 the same concept in SQL. And you would not need a list as the first 
 argument. Just pass multiple arguments and return the first set value.
 
 $var = var_set($_GET['var'], $_POST['var'], 'default');

Even better.

 http://en.wikipedia.org/wiki/Null_%28SQL%29#COALESCE

-- 
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
http://www.phcomp.co.uk/contact.php
#include std_disclaimer.h

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



Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Hannes Landeholm
This discussion is equivalent to the one that we just had. Read the thread
[PHP-DEV] Implicit isset/isempty check on short-ternary operator.

Also the $var = var_set($_GET['var'], $_POST['var'], 'default'); syntax
you propose would be equivalent to (as per previous discussion):

$var = $_GET[?'var'] $: $_POST[?'var'] $: 'default';

(The syntax might also be [?'var'], ['var'?] or different).


On 20 April 2011 18:19, Alain Williams a...@phcomp.co.uk wrote:

 On Wed, Apr 20, 2011 at 11:06:47AM -0500, Brian Moon wrote:
  It might be nice to extend it such that if the 1st argument is a list
 then
  the
  first in the list which is set is returned, eg:
  
   $var = var_set(($_GET['var'], $_POST['var']), 'default');
 
  If that is the usage, I would suggest coalesce() to be consistent with
  the same concept in SQL. And you would not need a list as the first
  argument. Just pass multiple arguments and return the first set value.
 
  $var = var_set($_GET['var'], $_POST['var'], 'default');

 Even better.

  http://en.wikipedia.org/wiki/Null_%28SQL%29#COALESCE

 --
 Alain Williams
 Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT
 Lecturer.
 +44 (0) 787 668 0256  http://www.phcomp.co.uk/
 Parliament Hill Computers Ltd. Registration Information:
 http://www.phcomp.co.uk/contact.php
 #include std_disclaimer.h

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




Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Ferenc Kovacs
On Wed, Apr 20, 2011 at 7:14 PM, Hannes Landeholm landeh...@gmail.comwrote:

 This discussion is equivalent to the one that we just had. Read the thread
 [PHP-DEV] Implicit isset/isempty check on short-ternary operator.


except that it wouldn't bring new syntax.

ps: please don't top post if everybody else does bottom or inline posting,
it's hard to follow.

Tyrael


Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread Mark
On Wed, Apr 20, 2011 at 6:00 PM, Jonathan Bond-Caron jbo...@openmv.comwrote:

 On Wed Apr 20 10:55 AM, Mark wrote:
 
  function varset($arr, $key, $default = '') { return (isset($arr[$key])
  ? $arr[$key] : $default); }
 
  where the call would be:
  $var = varset($_GET, 'var');
 
  I personally like both ways...
  My proposal is to make this function a core php function in PHP 5.4.
  The added benifit is obvious. People can, with this, use a way shorter
  notation to validate if a given array element exists. Right now that
  needs to be done with a ternary, filter_var or some other method
  (there are quite a few ways to check for existence).
 
  I tried to look in the PHP source to see if i could make a patch to
  add this but i couldn't find the function that defines the isset
  function (i wanted to base it on that). So a pointer to the right
  location would be nice (along with docs that tell me what i all need
  to do to implement a new php function).


 https://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_language_parser.y?rev
 ision=306938view=markup

 Look for isset_variables:, then zend_do_isset_or_isempty

 isset() lives in the parser and requires some advanced knowledge of the
 opcodes (personally I'm not there yet)


Oh boy, i never ever did anything in the core PHP coding so i'm certainly
not likely to be able to understand all of that. (yet)


 
  So, what do you think of this?
 

 I like the idea, it could also be called vardef() or var_default()



@ the rest.
The list idea is nice, but i don't really see the added value for it.. Lets
keep it simple, oke :)
As for that other thread: [PHP-DEV] Implicit isset/isempty check on
short-ternary operator
I don't really know much of it, but does that mean that my suggestion is
rejected even before i made an RFC for it?

Regards,
Mark


Re: [PHP-DEV] Function proposal: varset

2011-04-20 Thread D. Dante Lorenso

On 4/20/11 9:55 AM, Mark wrote:

Hi,
This proposal is for the often called line like this:
$var = isset($_GET['var']) ? $_GET['var'] : '';
Only a shorter and imho a cleaner solution to get the same:
$var = varset($_GET['var']);

The implementation for this in PHP code is this:

# Arg 1 = the variable to check for existence
# Arg 2 = the default return value which is an empty string by default

function varset($var, $default = '')
{
return (isset($var) ? $var : $default);
}


I proposed something similar over 5 years ago.  It ain't gonna happen 
because PHP language can't support it.  The Zend engine needs to be 
rewritten to remove the warnings and that's not something they are 
volunteering to do no matter how much people want it.


  http://markmail.org/message/yl26ebzcix35wtke

My proposal was called filled since it was the opposite of empty 
which already existed.  I extended the function to return the first 
non-empty value or null if all values evaluated as empty.


You could use the function like this:

  $x = filled($_GET['x'], $obj-something, $default, 'default');

It would return the first argument where !empty($arg) evaluates as TRUE.

There would need to be a companion function to check 'isset' opposite as 
you have proposed.


Like I said, though, I don't think this can be done in the language 
because I think they ran out of OPCODES and would have to tear apart the 
whole PHP engine to support such a feature.


-- Dante

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