Re: [PHP-DEV] A new idea on PHP6.

2012-07-19 Thread D. Dante Lorenso

On 7/19/12 1:17 AM, Ronald Chmara wrote:

With PHP 6, lets start with a:
Pure
Object
Oriented
PHP


OMG, did you seriously just recommend POOP?  LOL, I'm gonna go die now.


-- Dante

D. Dante Lorenso
da...@lorenso.com
972-333-4139

--
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 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



[PHP-DEV] proposed access modifier silent ... was: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator

2011-04-10 Thread D. Dante Lorenso
The problem with implementing ifsetor, filled, or ?? in userland 
is that the not set or undefined warning is fired before the 
variable is passed to the underlying function/method.


Is it possible to add a modifier that turns off warnings for undefined 
variables whenever that specific method is called?  Something like:


class Utility {
  public silent function filled() {
$args = func_get_args();
foreach ($args as $arg) {
  if (!empty($arg)) { return $arg; }
}
return false;
  }
}

$x = Utility::filled($my_undef, $x['undef'], $nosuch, 'default');

The modifier silent will turn all undefined or not isset() variables 
into NULL values when being passed to the method and no warnings will be 
issued.


Then, we can build our own damn functions as we see fit without the fuss.

-- Dante

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



Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator

2011-04-09 Thread D. Dante Lorenso

On 4/7/11 5:35 PM, Etienne Kneuss wrote:

On Apr 07 18:03:48, Rasmus Lerdorf wrote:

On 4/7/11 5:59 PM, Matthew Weier O'Phinney wrote:

It may change the semantics as they stand, but I'd argue that the
_expectation_ from the shorthand ternary is to shorten code that
currently uses isset(). As it is, I have almost no use for it at this
point, as I end up needing to do:

  $value = isset($a[$key]) ? $a[$key] : 'Not set';

which is exactly the situation I had before it was introduced.


Not sure why you would have that expectation. The long ternary doesn't
do that, and there is nothing about the short ternary that changes that.
There was talk of a new ifsetor type of operator to have those semantics
but never any talk of changing existing semantics.


Well it could (and I believe that was the intention) call !empty instead
of isset, that way the semantics would not be changed, appart from the
lack of error for undefined variables.



Since I see the beast has risen from the dead, I'd like to chime in 
again for my proposal to have a function called filled.  It is the 
opposite of empty() and takes variable number of arguments.  The first 
non-empty value is returned.  example:


$x = filled($myarray['badkey'], $varundef, $obj-nosuch, $default);

This *must* be created in the Zend engine because userland can not catch 
the unset keys and variables.


Again, filled() would be the opposite of empty() and we'd need some 
other function similar to be the opposite of isset() if you wanted that 
type of check.  The proposed filled() will suit all my needs with great 
satisfaction :-)


-- Dante

--
D. Dante Lorenso
da...@lorenso.com
972-333-4139

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



Re: [PHP-DEV] suggestion about ternary operator

2009-11-21 Thread Dante Lorenso
I would love to restate my recommendation for the function filled.
Which is the opposite of empty.  Filled would accept a variable
number of arguments and return the first where empty evaluates as
false.

Like empty, filled would not throw notices for undefined variables.
This is not the same as the ifsetor debate because filled is opposite
empty and cares not about isset.

-- dante

On 11/21/09, Rasmus Lerdorf ras...@lerdorf.com wrote:
 Alban wrote:
 Le Sat, 21 Nov 2009 09:48:10 +0100, Lukas Kahwe Smith a écrit :

 On 21.11.2009, at 06:12, Alban wrote:

 This is not a big problem but if a solution exists, this would be so
 cool ! Especialy when we have to check existance of twenty or more key
 in array. Code would be be lighter and clear. Since i use PHP, I always
 have in my 'common function file' a function like that :

 function getIssetVar($var, $default) { return ((isset($var)) ? $var :
 $default); }

 So is it possible to make a little improvement on this operator or
 introduce a new operator or a core function which do that ? What's your
 feeling about it ?

 this feature request has already been discussed and declined:
 http://wiki.php.net/rfc/ifsetor

 please review this rfc before continuing this thread.

 regards,
 Lukas Kahwe Smith
 m...@pooteeweet.org

 Thanks for the link to the RFC :)

 Excuse me, but I'll be little hard in this post. This for insult the
 community but I want the community really think about the decision it
 made and the reason why.

 I also read why it have been refused here :
 http://www.php.net/~derick/meeting-notes.html#ifsetor-as-replacement-for-
 foo-isset-foo-foo-something-else

 Is it serious ?

 «
 The name for this new operator is heavily disputed and we could not agree
 on a decent name for it.
 »

 Tomorrow I will not send food to the association for children who are
 hungry because I can not choose between offering Thai or basmati rice.

 Stop sarcasm, seriously, this is not an honorable response from people
 making decisions. Take your responsibility and make a vote or impose a
 name, just do it.

 «
   Instead of implementing ifsetor() we remove the
   requirement for the middle parameter to the ?: operator.
 »

 That's not people wants and that's not do their need.
 So that not a correct answer of the php developper demand.

 «
   In combination with the new input_filter extension
   you then reach the original goal of setting a default
   value to a non-set input variable with:

   $blahblah = input_filter_get(GET, 'foo', FL_INT) ?: 42;
 »

 I don't see how do that with the actual filter extension. Even if it is
 possible, this is not a pretty short and easier solution than :

 $var = (isset($var)) ? $var : 'default';

 The ternary isn't meant to solve the isset thing you are talking about.
  It is simply a shortcut to normal ternary operations.  The most common
 case where you don't know if a variable is set is on the initial input
 via $_GET or $_POST and we definitely don't want people doing:

   $var = $_GET['foo'] ?: 42;

 It would be an XSS disaster.  Hence the suggestion to use input_filter
 there, or a similar user-supplied filtering function in which case the
 ternary, as it is currently implemented, is perfectly suitable.

 -Rasmus


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



-- 
Sent from my mobile device

D. Dante Lorenso
da...@lorenso.com
972-333-4139

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



Re: [PHP-DEV] suggestion about ternary operator

2009-11-21 Thread D. Dante Lorenso

Lukas Kahwe Smith wrote:

On 21.11.2009, at 22:29, Dante Lorenso wrote:


I would love to restate my recommendation for the function filled.
Which is the opposite of empty.  Filled would accept a variable
number of arguments and return the first where empty evaluates as
false.

Like empty, filled would not throw notices for undefined variables.
This is not the same as the ifsetor debate because filled is opposite
empty and cares not about isset.



did you even read the RFC?


Yes I did, and all I see is this in the References section:

  Suggestion to leave an empty() variant out of the picture since
   this  feature can be implemented in userland, though this of
   course not provide the full functionality of empty() which
   does not trigger notices for missing variables

I didn't see my proposal listed in it anywhere.  See this recommendation 
 from 3 1/2 years ago:


  - May 03, 2006
http://www.mail-archive.com/internals@lists.php.net/msg21617.html

Can someone please add the 'filled' proposal to the RFC?  I find 
'filled' way more useful than 'ifsetor' because in everyday code, I am 
constantly wanting to assign default values to variables that don't have 
values for a variety of reasons.  The assignment of a default value 
happens before input filtering.


  $email = filled(
$_REQUEST['email'],
$CONFIG-email_default,
$class_email,
'defa...@domain'
  );

Give me the first non-empty value and don't throw NOTICE warnings about 
it.  Otherwise, I need all this:


   $email = !empty($_REQUEST['email']) ? $_REQUEST['email'] : (
!empty($CONFIG-email_default) ? $CONFIG-email_default : (
!empty($class_email) ? $class_email : 'defa...@domain'
   ));

Yuck.

-- Dante

--
D. Dante Lorenso
da...@lorenso.com
972-333-4139

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



Re: [PHP-DEV] The constant use of isset()

2009-05-12 Thread D. Dante Lorenso

Ólafur Waage wrote:

While researching for this suggestion I found this rfc proposal regarding
ifsetor() ( 
http://wiki.php.net/rfc/ifsetor?s[]=issethttp://wiki.php.net/rfc/ifsetor?s%5B%5D=isset)
and it's rejection point was that it was currently not possible (
http://marc.info/?l=php-internalsm=108931281901389w=2 )

But would it be possible to check for a value of a variable if it is set?

Since I often do (and see others do)

if(isset($_GET[foo])  $_GET[foo] == bar)
or even worse
if((isset($_GET[foo])  $_GET[foo] == bar) || (isset($_GET[baz]) 
$_GET[baz] == bat))

to be able to do something like this

if(isset($_GET[foo]) == bar)
or
if(isset($_GET[foo]) == bar || isset($_GET[baz]) == bat)

That isset (or some other language construct) would return the variable if
it were set and false if it was not.

Thanks for your time, i know this has probably been talked to death in one
form or other.


Yes.  Beaten it has been.  I still want my function:  filled(...).  I 
described the spec here:


  http://marc.info/?l=php-internalsm=114677154729359w=2

You would use it like the opposite of empty but it takes an arbitrary 
number of parameters and returns the first value where empty() would 
evaluate as false.  Like isset() and empty(), it would do so without 
throwing any notices:


  $x = filled($y[maybe], $obj-tryit, $z['a']['b']['c'], $default);

Would it be a timesaver and very useful?  You bet!  That was 2006.  Good 
luck getting anything changed.


-- Dante

--
D. Dante Lorenso
da...@lorenso.com

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



Re: [PHP-DEV] Making PHP upload hooks available through session variables?

2008-07-31 Thread D. Dante Lorenso

Tore B. Krudtaa wrote:

I would like to be able to use the upload hooks without installing the APC.
I would eventually like to be able to use those upload hooks using session 
variables.


Maybe you can avoid the problem entirely.  I was using the 
uploadprogress PECL extension (which I believe also leveraged the 5.2 
hooks) for a year or so until I found this upload progress meter written 
using Flash and Ajax:


  http://digitarald.de/project/fancyupload/

If you follow the mailing archives, there's been great debate whether a 
feature like upload progress monitoring belongs in PHP (server side) or 
in your browser (client side).  I like server-side control, but after 
experiencing the Fancy Upload 2 embedded into my current web project, I 
love it and have no reason to go back to the old PHP-way.


FU2 (not my acronym) does require Flash 9, but my site already makes 
this dependency.  If you can accept those reqs, FU2 also supports 
multiple file uploads and can give progress feedback for all files as a 
whole.


-- Dante


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



Re: [PHP-DEV] Making PHP upload hooks available through session variables?

2008-07-31 Thread D. Dante Lorenso

Tore B. Krudtaa wrote:

To D. Dante Lorenso:
Thanks for notifying me of:
http://digitarald.de/project/fancyupload/
But I would still like to see the upload hooks accessible from within a 
standard PHP inst., which would give me more control of the upload progress as 
well as more control in the feedback to the client, and it would be even more 
browser compatible.


A year or so ago, I too wanted the ability to track incoming media 
uploads.  I wanted to build an admin page which would show me a list of 
all users that are currently uploading media and how far into the 
process they had gone.


For a multimedia site like my http://www.pubclip.com/, I could 
potentially have several dozen users uploading videos up to 256MB each. 
 If I needed to restart a server or do maintenance, it would be nice to 
check that those users weren't already at 90% of their upload and would 
lose all progress if I restarted a machine.


I imagined a hook/callback that would just log the userid, file size, 
uploaded-so-far size, and other light meta data to some storage location 
(memcached, postgresql, mysql, flat file, etc) which an admin could 
scoop up for a quick overview of what's going on.



So what about the PECL uploadprogress:
Same problem as when using APC, my customers PHP inst. does not have this 
installed and nothing I can do about that PHP inst.


It sounds like if you can not modify the PHP installation, you'll need 
to find a client-side only solution.  If feedback to a user on his OWN 
upload is all you want, the client-side solution is sufficient.  If the 
customer is using your application, just require Flash and Javascript in 
order to allow uploads using the fancy uploader.  Provide a crappy, 
non-fancy uploader for users refusing to install Flash.


Client-side feedback should really be built into browsers since it's 
information that only the client needs.  We already have data for 
downloads that project time remaining, etc.  Tell Mozilla/Firefox, and 
IE teams to implement this for uploads also.


My example of when an admin needs the upload progress data on the server 
is one of the rare examples when you actually NEED the callback hooks in 
PHP since there is no other way to gather the data without trusting 
clients to periodically come tell you.


-- Dante



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



Re: [PHP-DEV] New string functions: str_startswith() and str_endswith()

2008-07-21 Thread D. Dante Lorenso

Jani Taskinen wrote:

Paweł Stradomski kirjoitti:

W liście Rasmus Lerdorf z dnia poniedziałek, 21 lipca 2008:

It also isn't any shorter:

   if(str_endswith($path,'.php'))

   vs.

   if(substr($path,-4)=='.php')


Only if comparing to a static string, but not for this case:

if (substr($path, -strlen($extension)) == $extension)
Readability would also increase.

You people are funny..


I'd like to have such a function in PHP, but when you think about how 
easy it is to create without bloating the PHP core, it's easy enough to 
do without it.  Here's what I do using my own string library:


  if (LS_Util_String :: ends_with($path, '.php')) {
   ...
  }

It's a bit longer, but all my functions are longer for good reason:
http://www.dantescode.com/2007/10/10/evolution-of-php-coder-naming-classes/

-- Dante

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



[PHP-DEV] Re: Traits for PHP ... Why can't every Class be a Trait?

2008-02-21 Thread D. Dante Lorenso

All,

I can imagine a case where you would want to box common functionality 
into a trait and be able to use that trait as a class also.  Will we end 
up with a lot of classes like this?:


class SomeClass {
  use SomeTrait;
}

What's wrong with making all 'Class'es be 'Trait's and the only thing 
which makes a Trait a Trait is when you use it as such?


class MyClass {
  trait SomeClass;
}

In other words, why mustn't a trait be instantiable?  Why can't every 
Class be a Trait?


-- Dante

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



Re: [PHP-DEV] Re: Traits for PHP ... Why can't every Class be a Trait?

2008-02-21 Thread D. Dante Lorenso

Stefan Marr wrote:

Hi,

D. Dante Lorenso schrieb:

All,

I can imagine a case where you would want to box common functionality 
into a trait and be able to use that trait as a class also.  Will we 
end up with a lot of classes like this?:


class SomeClass {
  use SomeTrait;
}

What's wrong with making all 'Class'es be 'Trait's and the only thing 
which makes a Trait a Trait is when you use it as such?


class MyClass {
  trait SomeClass;
}

In other words, why mustn't a trait be instantiable?  Why can't every 
Class be a Trait?


Well, the trait concept is not a silver bullet for all problems out there.
What is wrong with inheritance or delegation for reusing complex 
behavior? Traits are for finer grained reuse in my eyes.
The usage I've seen so far suggests typical traits are about 1 to 5 
methods, but the average method count on a trait would be 1.88 or 
something like this (just a rule of thumb. from what I personally have 
looked at).


I agree Traits are cool for what they do.  I'm saying that we don't need 
to introduce a new thing called a Trait just to do what traits are doing.


The magical part of Traits is the flattening of included class 
components.  Just do this flattening with things defined as a Class and 
we won't have to introduce yet another kind of thing.


Not all classes are meant to work as traits but the ones created with 
being a trait in mind would.  If you create a Class/Trait with 5 
methods, fine.  But you could just as easily create one with 50 methods.


Current Class + New Trait features = new Class

All you need to implement is the flattening declaration code:

--
class MyClassWhichCouldBeATrait {
...
}
class MyClass {
   suck MyClassWhichCouldBeATrait;
}
--

BTW, can we add 'suck' to the list of alternate keywords ;-)

-- Dante

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



Re: [PHP-DEV] Extending SAPI specific php.ini to include, at least, major version.

2006-06-12 Thread D. Dante Lorenso

Richard Quadling wrote:

But the issue of having the same php.ini for PHP5 and PHP6 (both are
php-isapi.ini) is a pain and stops me from playing with them together.


Can't you just configure PHP when you compile it with the following option:

  ./configure ...
   --with-config-file-path=/path/to/php6ini/ \
   ...

Then specify your own PHP ini search path and use different ones for each
version you compile.  No changes to PHP, and your problem is solved.

Dante

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



[PHP-DEV] extension can not receive unset values without E_NOTICE or reference creation

2006-05-26 Thread D. Dante Lorenso

All,

Back on the topic of trying to write a 'filled' function in an 
extension, I have run into trouble.  I have declared a function as follows:


-- 8  8 --
static
   ZEND_BEGIN_ARG_INFO(all_args_prefer_ref, ZEND_SEND_PREFER_REF)
   ZEND_END_ARG_INFO()

zend_function_entry shorthand_functions[] = {
   PHP_FE(filled, all_args_prefer_ref)
   {NULL, NULL, NULL}  /* Must be the last line in 
shorthand_functions[] */

};

PHP_FUNCTION(filled)
{
   RETURN_TRUE;
}
-- 8  8 --

Then, in PHP I try the following test code:

-- 8  8 --
?php
$x = array();
$x[dog] = spot;
$x[cat] = moriss;
print_r($x);

// testing
print filled(testing, $x[pig], $y-testing);
print \n;

print_r($x);
print_r($y);
?
-- 8  8 --

Unfortunately, $x now contains a 'pig' key and the non-existent $y has 
been transformed into an object:


-- 8  8 --
Array
(

   [dog] = spot
   [cat] = moriss
)
1
Array
(
   [dog] = spot
   [cat] = moriss
   [pig] = 
)

stdClass Object
(
   [testing] = 
)


-- 8  8 --

Is there a way to define the parameters which an extension's function 
will accept to be optionally set?  The prefer-by-ref I am using is 
making the var exist even when I don't want it to.


Dante

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



Re: [PHP-DEV] Re: extension can not receive unset values without E_NOTICE or reference creation

2006-05-26 Thread D. Dante Lorenso

Pierre wrote:

On Fri, 26 May 2006 15:45:19 -0500
[EMAIL PROTECTED] (D. Dante Lorenso) wrote:
Back on the topic of trying to write a 'filled' function in an 
extension, I have run into trouble.  I have declared a function as

follows:


It is perfectly normal and desired.
  


Not desired.


The variable is fetched before entering your function. This fetch
operation raises a E_NOTICE, create/initialize the ZVAL and pass it to
your function.
  


You miss the point.  If the ZVAL was created and initialized already, 
then I wouldn't be performing this exercise.  It is because the ZVAL has 
not been created that I am writing this extension.


Dante

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



Re: [PHP-DEV] Re: left/right order of assignment and ++ increment changed? 5.0.x --5.1.x

2006-05-25 Thread D. Dante Lorenso

Sara Golemon wrote:
Seems the order or left vs right assignment evaluation has changed 
somehow recently in my upgrade to PHP 5.1.4.  See the following code:


That's is indeed a quirk of a change in the way variables are 
retreived/stored between 5.0 and 5.1.
Is it an unexpected BC break? In functional terms yes, but technically 
no. As mike already replied, using the same var more than once in a 
single expression where the value of the variable is expected to 
change is (and has always been) considered undefined behavior.  I'd 
recommend changing your statement to:

$data[$index] = $index;
++$index;

And before you complain about the extra work for the engine, let me 
just mention this is still lighter weight than what 5.0 and 4.x were 
doing.


No complaints here.  This is a change I can easily work around and don't 
mind the BC breakage.  Just wanted to illuminate the error to internals 
just in case it would reflect upon possible breakage elsewhere.  I 
worked around the undefined behavior before the first email was sent ;-)


Keep up the good work all.

Dante

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



[PHP-DEV] Is PostgreSQL 8.1.3---8.1.4 necessary for 'properly' escaped coders?

2006-05-24 Thread D. Dante Lorenso
All, 

I use PostgreSQL 8.1.3 extensively.  Currently all my PHP 5.1.4 code is using the pgsql extension to connect.  My newer development code is connecting through the newer PDO/pgsql extension.  


Is the PostgreSQL 8.1.4 SQL injection bug fix necessary if I've been well 
behaved by passing *all* sql values through either of these escaping functions?:

   * pgsql: pg_escape_string(...)
   * PDO: bindValue(..., ..., ...)

A question similar was recently posted over in general, but I didn't see any response and a reply suggested we ask internals.  


See the recent Slashdot post:

==
Developers: PostgreSQL 8.1.4 Released to Plug Injection Hole
==
Posted by [1]ScuttleMonkey on Tuesday May 23, @09:42PM from the
good-little-dutch-boy dept.
alurkar writes to tell us that PostgreSQL released version 8.1.4 today
in order to combat a security flaw allowing a [2]SQL injection attack.

From the article: The vulnerability affects PostgreSQL servers

exposed to untrusted input, such as input coming from Web forms, in
conjunction with multi-byte encodings like (Shift-JIS (SJIS), 8-bit
Unicode Transformation Format (UTF-8), 16-bit Unicode Transformation
Format (UTF-16), and BIG5. In particular, Berkus says that
applications using 'ad-hoc methods to escape strings going into the
database, such as regexes, or PHP3's addslashes() and magic_quotes'
are particularly unsafe. 'Since these bypass database-specific code
for safe handling of strings, many such applications will need to be
re-written to become secure.'

[1] http://slashdot.org/~ScuttleMonkey/
[2] http://www.newsforge.com/article.pl?sid=06/05/23/2141246
[3] http://developers.slashdot.org/developers/06/05/23/2228225.shtml
[4] http://developers.slashdot.org/developers/06/05/23/2228225.shtml
[5] http://developers.slashdot.org/article.pl?sid=06/05/23/2228225threshold=-1
[6] http://developers.slashdot.org/

Dante

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



[PHP-DEV] left/right order of assignment and ++ increment changed? 5.0.x -- 5.1.x

2006-05-24 Thread D. Dante Lorenso

Internals,

Seems the order or left vs right assignment evaluation has changed 
somehow recently in my upgrade to PHP 5.1.4.  See the following code:


-- 8  8 --
?php
$data = array();
$index = 0;
for ($x = 0; $x  5; $x++) {
  $data[$index] = $index++;
}
print_r($data);
?
-- 8  8 --

in PHP 5.0.5:

Array
(
  [0] = 0
  [1] = 1
  [2] = 2
  [3] = 3
  [4] = 4
)

in PHP 5.1.4:

Array
(
  [1] = 0
  [2] = 1
  [3] = 2
  [4] = 3
  [5] = 4
)

Is this a bug, a feature, or bad programmer [me]?

Dante

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



Re: [PHP-DEV] private, protected, readonly, public

2006-05-18 Thread D. Dante Lorenso

Jeff Moore wrote:

On May 16, 2006, at 7:28 PM, D. Dante Lorenso wrote:
I'm not familiar with this OOP concept from any other language.  
Perhaps it exists, but if it doesn't, is there a reason why?
Its hard to find a major OO language that does not have 
property/accessor method support.


It's not the p, p, p, __get or __set I was unfamiliar with.  It's the 
'readonly' construct that I had not seen in any other language.


The Pandora's box of complexity was opened when PHP got __get and 
__set.  readonly or readable is just a bandaid that fixes one use case 
of one problem, but does it in a way that doesn't help fix any of the 
other problems in the future. There is nothing wrong with simple 
properties in PHP just the way they are now.  There is also nothing 
wrong with __get or __set.  They work well when you truly need virtual 
properties, such as for an active record or a proxy class.


Sounds like you are against adding 'readonly'.

What PHP is missing is a way to associate individual accessor methods 
with individual properties ...


Isn't that what you do when you define the class without using __get and 
__set?


   class A { private $x; public $y; protected $z; function x() { return 
$this-x; } ... }

   $A = new A();

To associate an 'accessor method' with a property other than using the 
$A-x syntax, you just put () at the end of the call as in: $a-x() and 
now you have a method call.  Seems like we don't need anything new in 
the language for that.


I thought this thread was about wanting to create some new hybrid 
visibility/access level other than p/full, p/full, and p/full.  
Something along the lines of declaring different levels of access to 
variables based on visibility such that:


   * public readable, but also protected readable/writable
   * protected readable, but also private readable/writable

Although that sounds like fun, I'm all about duplicating what other 
languages have and find useful than inventing new oop concepts for the 
fun of academic exercise.


Dante

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



Re: [PHP-DEV] private, protected, readonly, public

2006-05-16 Thread D. Dante Lorenso

Marcus Boerger wrote:

btw, i wonder where the people are that usually complain about my patches?
Is this finally something most people like?
  


Maybe you built a nuclear power plant.

Dante

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



Re: [PHP-DEV] private, protected, readonly, public

2006-05-16 Thread D. Dante Lorenso

Jason Garber wrote:

CS Does anyone apart from me wonder why we need to bloat the language for
CS an obscure feature like this? Please take a step back, take a deep 
CS breath, count to 10 and that's *really* what the PHP community has been

CS waiting for.

Please consider that not everyone does the same things with PHP that
you do - you apparently haven't run into the need for it.

That's okay, but others have.
  


I'm not familiar with this OOP concept from any other language.  Perhaps 
it exists, but if it doesn't, is there a reason why?


If you add a language construct like 'readable' or 'readonly' wouldn't 
that almost begin to require the need for reflection functions to go 
along with it:


   is_readable($object, $key)

Or something like that?

Dante

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



[PHP-DEV] xmlwriter_write_raw() not in 5.1.4 yet?

2006-05-15 Thread D. Dante Lorenso
I'm on the latest and greatest PHP 5.1.4.  I can see the function I 
think I want in the manual:


  http://us3.php.net/manual/en/function.xmlwriter-write-raw.php

But the manual says it's only in CVS.  I confirmed that I don't have it:

   * Fatal error: Call to undefined function xmlwriter_write_raw() in
 ***.php on line **

I am hoping that this function would let me merge already-created XML 
into the XML I am writing and avoid the , , , etc escaping of content 
which is normally done when using xmlwriter_text().  Zend summary was 
talking about it back in December.  We've had a couple version updates 
since then.  Still not in the official release?


   * http://www.zend.com/zend/week/week268.php#Heading8

Anyone know the status of this function, if it does what I want, and 
what version I can start using it?


Dante

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



Re: [PHP-DEV] xmlwriter_write_raw() not in 5.1.4 yet?

2006-05-15 Thread D. Dante Lorenso

Jared Williams wrote:

http://us3.php.net/manual/en/function.xmlwriter-write-raw.php

Anyone know the status of this function, if it does what I 
want, and what version I can start using it?

I originally requested it. http://pecl.php.net/bugs/bug.php?id=6267 . I think 
it'll appear in 5.2,
http://oss.backendmedia.com/PhP52 . Jared


Let me double-check that this does what I think it does.  Take this code 
for example:


?php
//--
// build img src=http://us2.php.net/images/php.gif; width=120 
height=67/

$I = xmlwriter_open_memory();
xmlwriter_start_element($I, img);
xmlwriter_write_attribute($I, src, http://us2.php.net/images/php.gif;);
xmlwriter_write_attribute($I, width, 120);
xmlwriter_write_attribute($I, height, 67);
xmlwriter_end_element($I);
$IMG_XHTML = xmlwriter_output_memory($I);

// build a href=http://www.php.net;{REPLACE_ME}/a
$A = xmlwriter_open_memory();
xmlwriter_start_element($A, a);
xmlwriter_write_attribute($A, href, http://www.php.net/;);
xmlwriter_text($A, {REPLACE_ME});
xmlwriter_end_element($A);
$A_XHTML = xmlwriter_output_memory($A);

// merge XML parts together
$xml_str = str_replace({REPLACE_ME}, $IMG_XHTML, $A_XHTML);
print htmlspecialchars($xml_str);
// a href=http://www.php.net/;img 
src=http://us2.php.net/images/php.gif; width=120 height=67//a

//--
?

Instead of having to merge the two XML strings back together, I could 
write something like this instead?:


?php
//--
// build img src=http://us2.php.net/images/php.gif; width=120 
height=67/

$I = xmlwriter_open_memory();
xmlwriter_start_element($I, img);
xmlwriter_write_attribute($I, src, http://us2.php.net/images/php.gif;);
xmlwriter_write_attribute($I, width, 120);
xmlwriter_write_attribute($I, height, 67);
xmlwriter_end_element($I);
$IMG_XHTML = xmlwriter_output_memory($I);

// build a href=http://www.php.net;$IMG_XHTML/a
$A = xmlwriter_open_memory();
xmlwriter_start_element($A, a);
xmlwriter_write_attribute($A, href, http://www.php.net/;);
xmlwriter_write_raw($A, $IMG_XHTML); // merge already created XML
xmlwriter_end_element($A);
$xml_str = xmlwriter_output_memory($A);

// merge already done
print htmlspecialchars($xml_str);
// a href=http://www.php.net/;img 
src=http://us2.php.net/images/php.gif; width=120 height=67//a

//--
?

I know this example is a little silly since a merge would never have 
been necessary, but in my current code, I often construct parts of XML 
documents inside other classes which need to all be stitched back 
together to yield the final XHTML output.  Being able to write 'raw' 
XHTML into an existing node is helpful.


Documentation on XMLWriter is very sketchy overall.  Looking at the 
extension source, I see that I can use this as an object 'new 
XMLWriter', but the documentation doesn't say anything about that.  When 
I wrap this functionality into my own custom XWriter object, I can 
create shorthand like this:


?php
//--
$XML = new XWriter(a, href, http://www.php.net;);
$XML-append(img, src, http://us2.php.net/images/php.gif;, width, 
120, height, 67);

$xml_str = $XML-toXML();
//--
?

I'll be writing an article on XWriter some time in the next month on my 
blog, but I need to use XWriter to create the blog software, first ;-)  
Having the ability to xmlwriter_write_raw() would be a big help in 
making XWriter more efficient.


Dante

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



Re: [PHP-DEV] private, protected, readonly, public

2006-05-12 Thread D. Dante Lorenso

Andi Gutmans wrote:

I can take any feature in PHP and add features :)


Is that an offer ;-)?  I've got a couple you can add, lol.

Dante


At 01:44 PM 5/12/2006, Jason Garber wrote:

Hello,

  PHP implements many features, and skips many features.  I think the
  rule of thumb needs to be that if a feature is implemented, finish
  it.

  For example, if you provide __get() and __set(), provide an
  efficient way of handling the normal use case.

  If you start triggering an E_NOTICE when an undefined variable is
  accessed, then provide an easy way to access variables that may or
  may not be set.

  If you provide a __tostring() method, then finish it so that is gets
  called when an object is cast to a string, concatenated with a
  string, as well as being output with echo, print.

  There are a lot of casual users of PHP.  There are also the people
  out there who are buying the Zend products, buying the MySQL support
  contracts, using PHP at Yahoo! -- the people who have chosen to use
  PHP OVER Java/.NET/Perl, because it is a great language -- the
  people who need the completed features because they are running
  multi-million-dollar businesses on this platform.


  Take a step back and truly evaluate why someone in a demanding
  situation might want every bit of performance and readability that
  they can squeeze out of *existing* language features.

  I'm not talking about adding hundreds of new features, or turning
  PHP into the next java.  It's about real business cases.

  It's not about what YOU WOULD NOT use, it's about what a lot of
  people need.

--
Best regards,
 Jason Garber   mailto:[EMAIL PROTECTED]
 IonZoft, Inc.

Friday, May 12, 2006, 3:16:27 PM, you wrote:

igc It seems to me this would be a great option to add. How 
difficult would it
igc be? Would it take significant editing of the source code? I 
don't see the
igc issue in adding it - seems like it would have plenty of places 
to be used.
igc Though, if it is added, the name 'readonly' seems a little 
misleading. It
igc gives off the idea of being able to set it, and not edit again, 
and not only

igc being able to edit it inside the class.

igc On 5/12/06, Hartmut Holzgraefe [EMAIL PROTECTED] wrote:

 Bastian Grupe wrote:
  Blame my recent use of Java here ;-)
 
  Well, I think the whole point of ppp is to having to use setters 
and

  getters consistently.

 i'm going to blame your use of Java for this one, ppp is way older
 than the setter/getter fashion and as far as i remember the main
 reason to introduce the setter/getter pattern into java was to
 have a standard way for Java IDEs to provide access to Java Bean
 properties in property dialogs in their GUI design tools

  I personally wouldn't like to be able to access some members 
which are

  private, and not others. It just *feels* wrong.

 Think of it as a more fine grained permission system, like unix
 file attributes. Reading and writing a property value are two
 different operations and it makes sense to distinguish access
 rights not only by ownership but also by type of operation.

  And I don't know whether or not less typing is really a good 
argument in

  this situation (think unreadable code in shortcut-ish programming
  languages).

 Less typing is not an argument by itself, else we'd all do APL

 But less typing is less error prone (and no, plese *don't* mention
 auto-completion here ;), it can be less readable, too, and in this
 special case it spreads information that should be in one place.
 Maintainability can become an issue, too.

 Take a look at typical PHP class implementations: they have
 all properties on top followed by the member functions. So to find
 out whether a private property is really provite or whether it has
 a getter or even a setter, too, i would have to browse the full
 class code.

class example {
  private $foo;
  private $bar;
  [... more properties ...]

  function __construct() {...}
  function __destruct() {...}

  function getFoo() {...}

  [... more code ...]
}

 So $foo is readonly here and $bar is really private. Or wait,
 maybe we have just overlooked getBar()?

 With

readonly $foo;

 on the other hand you have all the information in one place.

 If you want to go the getter/setter path all the way then we
 wouldn't need all the ppp stuff anymore alltogether, we would
 just make everything private and have the getter and setter
 decide (using instanceof on $this etc.) the access rights.


 --
 Hartmut Holzgraefe, Senior Support 
Engineer.

 MySQL AB, www.mysql.com

 Are you certified? http://www.mysql.com/training/certification

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






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



[PHP-DEV] allow extension writers to ignore E_NOTICE warnings about unset variables

2006-05-11 Thread D. Dante Lorenso

All,

Is there a way to define a function in an extension which would not 
require a passed in variable to exist?  In other words, can ZE be 
modified to allow extensions to not trigger E_NOTICE warnings if an 
unset variable is passed to a function which does not care if the var is 
set?


I can specify preferences about whether variables are passed by 
reference or not using macros like:


   * PHP_FE(..., first_arg_force_ref)
   * PHP_FE(..., third_arg_force_by_ref_rest)
   * PHP_FE(..., first_through_third_args_force_ref)

Which probably boil down somewhere into:

   * #define ZEND_SEND_BY_VAL 0
   * #define ZEND_SEND_BY_REF 1
   * #define ZEND_SEND_PREFER_REF 2

And I notice that if a variable is passed by reference to an extension 
function, no E_NOTICE is thrown.  Well, can we extend this concept 
further to say something like:


   * #define ZEND_SEND_WHO_CARES_IF_IT_EXISTS_OR_NOT 4

*but with a better name, of course*

Then, extension developers can write 'ifsetor', 'coalesce', and 'filled' 
as extensions (by themselves) and not need those specific functions 
added to the 'PHP core language' per-se.


Dante

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



Re: [PHP-DEV] allow extension writers to ignore E_NOTICE warnings about unset variables

2006-05-11 Thread D. Dante Lorenso

Antony Dovgal wrote:

On 12.05.2006 02:49, D. Dante Lorenso wrote:

* #define ZEND_SEND_BY_REF 1

This one is what you need.
I don't think it is.  The variable did not exist before the function was 
called and should STILL not exist afterwards.  I believe when you pass 
by reference, the variable will exist after the call.  This is bad since 
future calls to 'isset' will suddenly start returning TRUE when they 
shouldn't.


Dante

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



Re: [PHP-DEV] allow extension writers to ignore E_NOTICE warnings about unset variables

2006-05-11 Thread D. Dante Lorenso

Marcus Boerger wrote:

no, the compiler generates code that makes the executor generate the
variable and complain prior to performing the call.
  


The executor doesn't complain about unset variables prior to calling 
functions by reference, so I was thinking it could be modified to also 
not complain when calling functions that don't care about set 
variables.  Naturally, the unset variable would evaluate as NULL and be 
passed as such, just there would be no E_NOTICE.



In a zend extension you could try to hook into that process.
  


How do you mean?  Got any pointers?


Dante

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



Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-04 Thread D. Dante Lorenso

Rasmus Lerdorf wrote:

D. Dante Lorenso wrote:
In my PHP zen world, empty() and filled() are friends.  Ok, I've been 
selling 'filled()' for a while now.  Can we reverse the sell and try 
this .. why SHOULDN'T filled() be added to the language?
Because it doesn't do enough.  Unlike empty(), when there actually is 
something there, you have to check the type before using it anyway.

eg.
  $a = filled($_GET['a'],$_GET['b']);
You still have to do:
  if(!is_array($a)) echo $a;


You are correct that filled() does not serve the purpose of proper user 
input filtering.


filled() is not trying to solve the input filtering problem as much as 
it's trying to solve the problem of accessing array/object members in a 
cascading order of defaulting to a non-empty value.


Currently I have a 'hack' object called ObjArray() which I use to wrap 
maybe PHP arrays in order to access their array elements 'safely' (no 
E_NOTICE thrown) with options of a default value.  I use code like this:


   $maybe_array = function_which_returns_array_or_false();

   $obj = new ObjArray($maybe_array);
   print $obj-array_key;
   print $obj-get(array_key, $default_value);

The ObjArray class makes use of __get and __set functions to avoid 
tripping the E_NOTICE warnings that would occur otherwise when trying to 
access array properties that are not set.  In turn, ObjArray allows 
arrays to be accessed like objects.  ObjArray, however, can't be used on 
multi-level array access, but filled() could.


   print filled($maybe_array[array_key], $default_value);

That avoids having to wrap arrays inside objects and also allows more 
powerful accesses:


   print filled($maybe_array[array_key]-maybe_some_property, 
$default_value);


And unlike the pass-by-reference hacks, 
'$maybe_array[array_key]-maybe_some_property' will not magically come 
into existence after calling the filled() function.


INPUT FILTERING != filled()

The example of using $_GET and $_POST as arrays in my examples might be 
a bad idea.  In most cases, I plan to use filled() to set default values 
for arrays or objects which contain empty or non-set keys or 
properties.  Most times the variable being accessed is known to be a 
certain list of possible types and in one call to filled() I want to get 
the data I want or use a cascading set of defaults:


   define('HARD_CODED_CONSTANT', HARD_CODED);
   $filtered_user_input = get_safely_filtered_user_input_as_object();
   $database_row = fetch_database_row_as_array();
   $config_settings = fetch_config_file_as_array();

   $value = filled($filtered_user_input-thekey, 
$database_row[thekey], $config_settings[thekey], HARD_CODED_CONSTANT);


This works WITH input filtering especially when the default value is not 
just a default for the user input, but is a default for the chain of 
search locations.  I have many lines of PHP code which deal with if 
(!$variable) ..., if (!isset($array[key]) ..., if (empty($var))... 
trying to find defaults for data which does not exist or was not found.  
None of those deal with $_GET or $_POST user inputs.  Especially when 
moving into CLI development, $_GET and $_POST are irrelevant.


Because people could put ?a[]=1 in the GET args there and you have to 
check for that before using it.  That second type check defeats the 
purpose of filled() as far as I am concerned.  We need a quick way to 
do a check and default assignment without throwing a notice which is 
what ?: provides, then we need a decent way to check input arguments 
which is what pecl/filter is being brought into the core for (among 
other things).


People CAN do a lot of things (and some maliciously do).  I don't 
believe filled() prevents the input filtering from being added to the 
core.  Input filtering and filled() shared some commonality (selecting 
alternate values under specific conditions), but do not nullify the need 
for one or the other.


Detracting from my goal of having 'filled()' included in core, I'd have 
to say that as I see input filtering defined, that could be entirely 
written as part of Zend Framework in PHP and doesn't need to exist as 
part of the language core.  filled(), OTOH, must be written in 'zend' 
core because it simply can not be written as an extension or in 
userspace without triggering errors (undefined variables) or creating 
unwanted variables (pass by reference).


Dante

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



Re: [PHP-DEV] Specification for function filled() :: was ifsetor/coalesce

2006-05-04 Thread D. Dante Lorenso
The default value for 'filled()' if all values test TRUE for empty() 
should be FALSE, not NULL.  This is more consistent with the return 
values of empty().


Since filled() returns the first non-empty() value in the list of 
parameters provided, it works well when cast into a boolean context 
because the non-empty() value should evaluate as TRUE.  Example:


   filled(testing) // returns testing
   if (filled(testing)) {} // true
   filled(87) // returns 87
   (boolean) filled(87) // true

   $x[apple] = 42;
   filled($x[apple]) // returns 42
   filled($x[pear]) // returns false
   if (filled($x[apple]) !== false) {} // true
   if (filled($x[pear]) !== false) {} // false

Just wanted to chime in with an update in case 'filled()' can actually 
be considered.  I'd like everyone to consider this one function to be 
evaluated on it's merits alone and apart from any other functions which 
also might be wanted.  filled() is the opposite of empty() and is not 
dealing with tests for 'isset()'.  Another function should be proposed 
to solve that problem if it would still be needed after filled() is 
implemented.


Do I have any power to call a vote on this?

Dante


D. Dante Lorenso wrote:

Dear Internals,

I'd like a white bikeshed, but until you can decide on a color, how 
about we just build the bikeshed already.  Please consider the 
following specification:


== 8  8  8 ==

filled

(PHP 5.2.0)

filled - Find first non-empty value in a variable list where empty() 
evaluates as FALSE.


Description
--

mixed filled ( mixed varname [, mixed ...] )

filled() takes a variable number of parameters.  For each of these, 
*filled()* looks for a variable where !empty( varname ) evaluates as 
TRUE.  It returns the first non-empty value or NULL if all values are 
empty().


Note: filled() only checks variables as anything else will result in a 
parse error.  In other words, the following will not work: 
filled(trim($name)).
   filled() is the opposite of empty(), and no warning is generated 
when any one of the variables is not set.


Return Values
--

Returns first non-empty() value.

If all values are empty(), returns NULL.

Example
--
?php
echo filled($x[somekey], $_GET[getkey], $default, example);
echo filled(yes); // prints yes
filled(false); // returns NULL
echo filled($x[apple], $y, banana); // prints banana
$y = cat;
echo filled($x[apple], $y, banana); // prints cat
$x[apple] = pear;
echo filled($x[apple], $y, banana); // prints pear
unset($x[apple]);
echo filled($x[apple], $y, banana); // prints cat
?

See also empty()

== 8  8  8 ==

Dante



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



Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-03 Thread D. Dante Lorenso

D. Dante Lorenso wrote:
I don't think something like this can NOT be written in userspace 
because the 'isset' and 'empty' checks need to be run before arguments 
can be passed to a user function or warnings will start flying.  A 
function like this simplifies code which used to look like this:


   if (!empty($_POST[postkey])) {
   $value = $_POST[postkey];
   }
   elseif (!empty($_GET[getkey])) {
   $value = $_POST[getkey];
   }
   elseif (!empty($default_value)) {
   $value = $default_value;
   }
   else {
   $value = hard coded value;
   }

Into this:

   $value = coalesce($_POST[postkey], $_GET[getkey], 
$default_value, hard coded value);


I mean I DON'T think like this CAN be written in userspace.  And, yes, 
there is a bug in that code up above (around $_GET testing), but the 
'coalesce' function removes the test/set with identical values so 
removes those kinds of careless bugs.


Dante

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



Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-03 Thread D. Dante Lorenso

Johannes Schlueter wrote:

please search the archives for ifsetor.
  


I have completed this search and find:

   http://marc.theaimsgroup.com/?r=1w=2q=bl=php-devs=coalesce
   http://marc.theaimsgroup.com/?l=php-devw=2r=1s=ifsetorq=b

I am using PHP 5.1.2 currently and thought using pass-by-reference was 
frowned upon.  Assuming a mistaken assumption I move forward and see the 
following code which was presented to the list:


?php
function ifsetor($var, $value) {
   return (isset($var)) ? $var : $value;
}
print ifsetor($x, dante);
?

This works as I'd like in my dev environment, however, this does not 
solve the problem of allowing variable number of parameters (variables 
and values).  So, I've whipped up this 10 variable version:


?php
function ifsetor($var1, $var2, $var3, $var4, $var5, $var6, $var7, 
$var8, $var9, $var10) {

   if (isset($var1)) return $var1;
   if (isset($var2)) return $var2;
   if (isset($var3)) return $var3;
   if (isset($var4)) return $var4;
   if (isset($var5)) return $var5;
   if (isset($var6)) return $var6;
   if (isset($var7)) return $var7;
   if (isset($var8)) return $var8;
   if (isset($var9)) return $var9;
   if (isset($var10)) return $var10;
   return false;
}
print ifsetor($x[notset]-notset, $y[notset]-notset, $z-notset, 
dante);

?

PHP Fatal error:  Only variables can be passed by reference in 
.../ifsetor.php on line 15
PHP Warning:  Missing argument 5 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 6 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 7 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 8 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 9 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 10 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2


I can work around passing values by reference by calling the function 
like this:


   print ifsetor($x[notset]-notset, $y[notset]-notset, 
$z-notset, $temp = dante);


But you have to admit that's getting ugly and still, there are undefined 
parameters declared ... so then I tried it by assigning default values:


?php
function ifsetor($var1=null, $var2=null, $var3=null, $var4=null, 
$var5=null, $var6=null, $var7=null, $var8=null, $var9=null, 
$var10=null) {

   if (isset($var1)) return $var1;
   if (isset($var2)) return $var2;
   if (isset($var3)) return $var3;
   if (isset($var4)) return $var4;
   if (isset($var5)) return $var5;
   if (isset($var6)) return $var6;
   if (isset($var7)) return $var7;
   if (isset($var8)) return $var8;
   if (isset($var9)) return $var9;
   if (isset($var10)) return $var10;
   return false;
}
print ifsetor($x[notset]-notset, $y[notset]-notset, $z-notset, 
$temp = dante).\n;

print_r($x);
?

Now, $x, $y, and $z ARE set ...

   dante
   Array ( [notset] = stdClass Object ( [notset] = ) )

This is a nasty side-effect and can not be accepted.  I did not want to 
set these variables, just check their existance.


I am willing to go away and concede that this should be done in 
userspace IF you can show me that it is in fact possible.  The 2 
argument ifsetor is trivial in userspace, yes, but the variable case is 
more useful in a variety of situations and provides the most benefit to 
simplify code.  I did not find the answer in the archives.  Can you 
point me in the right direction?  I need to be able to do all of the 
following:


   * variable number of parameters
   * test 'isset' or 'empty'
   * testing variables and non-variable values (pass-by-reference won't
 work on values)
   * not have side-effect of defining values which are not already set
   * not trigger notices or warnings
   * returns value of first proper match

Dante


johannes

On Wednesday 03 May 2006 07:56, D. Dante Lorenso wrote:
  

All,

I'm sure this has been asked somewhere, but since I see requests for
features for 5.2 or 6.0, I'd like to add a simple item to the list
which would be quite useful to me and would simplify and clean up a lot
of code out there:

function coalesce(...)

This works much like in the SQL version of the same.  In SQL, the
function returns the first non-null argument from an arbitrary list.  In
our use, it should return the first non-empty value from the list:

Example:

$x = dante;
$y = ;
$z = ;

$value = coalesce($z, $y, $x); // $value = dante

This function would ideally be built into the language and bypass
warnings about undefined variables like 'empty' does.  It might be nice
to have several varieties of this function:

* return first parameter where empty() is FALSE
* return first parameter where isset() is TRUE

I don't think

Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-03 Thread D. Dante Lorenso

Eric,

This reply is too basic and is not the answer.  The problem is more 
complex then you have grasped.


The only way to remove the notice and warning errors is by using 
pass-by-reference in the userspace function.  Pass-by-reference can not 
be done for literal values and will only work on variables.  All notices 
and warnings have been thrown long before func_get_args can be run.  
Besides, func_get_args will return an array and then isset() and empty() 
no longer apply to the original variables.


Dante

Eric Coleman wrote:

http://us3.php.net/func_get_args
http://us3.php.net/array

Enjoy.

Eric Coleman


Eric Coleman

http://aplosmedia.com
home: 412 399 1024
cell: 412 779 5176


On May 3, 2006, at 3:13 AM, D. Dante Lorenso wrote:


Johannes Schlueter wrote:

please search the archives for ifsetor.



I have completed this search and find:

   http://marc.theaimsgroup.com/?r=1w=2q=bl=php-devs=coalesce
   http://marc.theaimsgroup.com/?l=php-devw=2r=1s=ifsetorq=b

I am using PHP 5.1.2 currently and thought using pass-by-reference 
was frowned upon.  Assuming a mistaken assumption I move forward and 
see the following code which was presented to the list:


?php
function ifsetor($var, $value) {
   return (isset($var)) ? $var : $value;
}
print ifsetor($x, dante);
?

This works as I'd like in my dev environment, however, this does not 
solve the problem of allowing variable number of parameters 
(variables and values).  So, I've whipped up this 10 variable version:


?php
function ifsetor($var1, $var2, $var3, $var4, $var5, $var6, 
$var7, $var8, $var9, $var10) {

   if (isset($var1)) return $var1;
   if (isset($var2)) return $var2;
   if (isset($var3)) return $var3;
   if (isset($var4)) return $var4;
   if (isset($var5)) return $var5;
   if (isset($var6)) return $var6;
   if (isset($var7)) return $var7;
   if (isset($var8)) return $var8;
   if (isset($var9)) return $var9;
   if (isset($var10)) return $var10;
   return false;
}
print ifsetor($x[notset]-notset, $y[notset]-notset, $z-notset, 
dante);

?

PHP Fatal error:  Only variables can be passed by reference in 
.../ifsetor.php on line 15
PHP Warning:  Missing argument 5 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 6 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 7 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 8 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 9 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2
PHP Warning:  Missing argument 10 for ifsetor(), called in 
.../ifsetor.php on line 15 and defined in .../ifsetor.php on line 2


I can work around passing values by reference by calling the function 
like this:


   print ifsetor($x[notset]-notset, $y[notset]-notset, 
$z-notset, $temp = dante);


But you have to admit that's getting ugly and still, there are 
undefined parameters declared ... so then I tried it by assigning 
default values:


?php
function ifsetor($var1=null, $var2=null, $var3=null, $var4=null, 
$var5=null, $var6=null, $var7=null, $var8=null, $var9=null, 
$var10=null) {

   if (isset($var1)) return $var1;
   if (isset($var2)) return $var2;
   if (isset($var3)) return $var3;
   if (isset($var4)) return $var4;
   if (isset($var5)) return $var5;
   if (isset($var6)) return $var6;
   if (isset($var7)) return $var7;
   if (isset($var8)) return $var8;
   if (isset($var9)) return $var9;
   if (isset($var10)) return $var10;
   return false;
}
print ifsetor($x[notset]-notset, $y[notset]-notset, $z-notset, 
$temp = dante).\n;

print_r($x);
?

Now, $x, $y, and $z ARE set ...

   dante
   Array ( [notset] = stdClass Object ( [notset] = ) )

This is a nasty side-effect and can not be accepted.  I did not want 
to set these variables, just check their existance.


I am willing to go away and concede that this should be done in 
userspace IF you can show me that it is in fact possible.  The 2 
argument ifsetor is trivial in userspace, yes, but the variable case 
is more useful in a variety of situations and provides the most 
benefit to simplify code.  I did not find the answer in the 
archives.  Can you point me in the right direction?  I need to be 
able to do all of the following:


   * variable number of parameters
   * test 'isset' or 'empty'
   * testing variables and non-variable values (pass-by-reference won't
 work on values)
   * not have side-effect of defining values which are not already set
   * not trigger notices or warnings
   * returns value of first proper match

Dante


johannes

On Wednesday 03 May 2006 07:56, D. Dante Lorenso wrote:


All,

I'm sure this has been asked somewhere, but since I see requests for
features for 5.2 or 6.0, I'd like to add a simple item

[PHP-DEV] Specification for function filled() :: was ifsetor/coalesce

2006-05-03 Thread D. Dante Lorenso

Dear Internals,

I'd like a white bikeshed, but until you can decide on a color, how 
about we just build the bikeshed already.  Please consider the following 
specification:


== 8  8  8 ==

filled

(PHP 5.2.0)

filled - Find first non-empty value in a variable list where empty() 
evaluates as FALSE.


Description
--

mixed filled ( mixed varname [, mixed ...] )

filled() takes a variable number of parameters.  For each of these, 
*filled()* looks for a variable where !empty( varname ) evaluates as 
TRUE.  It returns the first non-empty value or NULL if all values are 
empty().


Note: filled() only checks variables as anything else will result in a 
parse error.  In other words, the following will not work: 
filled(trim($name)).
   filled() is the opposite of empty(), and no warning is generated 
when any one of the variables is not set.


Return Values
--

Returns first non-empty() value.

If all values are empty(), returns NULL.

Example
--
?php
echo filled($x[somekey], $_GET[getkey], $default, example);
echo filled(yes); // prints yes
filled(false); // returns NULL
echo filled($x[apple], $y, banana); // prints banana
$y = cat;
echo filled($x[apple], $y, banana); // prints cat
$x[apple] = pear;
echo filled($x[apple], $y, banana); // prints pear
unset($x[apple]);
echo filled($x[apple], $y, banana); // prints cat
?

See also empty()

== 8  8  8 ==

Dante

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



Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-03 Thread D. Dante Lorenso

Rick Widmer wrote:

D. Dante Lorenso wrote:

Eric,
This reply is too basic and is not the answer.  The problem is more 
complex then you have grasped.

function ifsetor()  {
$args = func_get_args();
$count = count( $args );

for( $i=0; $i$count; $i++ ) {
   if isset( $args[ $i ] )) {
  return $args[ $i ];
   }

return false;
}




No, that doesn't address the problem.  See this:

-- 8  8  8 --
pre
?php
function ifsetor()  {
   $args = func_get_args();
   $count = count($args);
   for ($i=0; $i$count; $i++) {
   if (isset($args[$i])) {
   return $args[$i];
   }
   }
   return false;
}
print ifsetor($x, $y, $z, dante).\n;
?
/pre

PHP Notice:  Undefined variable: x in .../ifsetor.php on line 13
PHP Notice:  Undefined variable: y in .../ifsetor.php on line 13
PHP Notice:  Undefined variable: z in .../ifsetor.php on line 13
-- 8  8  8 --

See my post regarding a specification for 'filled()' as a function.  An 
important feature is that warnings about unset variables should not 
occur.  Your suggestion does not qualify.  This problem can not be 
solved in userspace.


Dante

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



Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-03 Thread D. Dante Lorenso

Jochem Maas wrote:

point 1: regardless of how people think there should be an ifsetor()
in the engine - the devs don't so there wont be one.

Avvhggghh!  Don't you just want to scream!


point 2: anything trying to implement this functionality in userspace
is a hack. (to stregethen that stance: Rasmus reiterated the point a few
days ago [can't remember which mailinglist] that people should be 
trying to
write *error free* code - ergo the error suppression is not a proper 
solution)


Ok.  You CAN NOT implement 'ifsetor/coalesce/filled' in userspace.  And 
the devs don't want it to exist ... so, WTF?

Dante, live with the hack. :-)
Translate to: Dante, you don't need PHP to be better, adequate is good 
enough.


soap box
Come on devs, I'm pleading with you.  Say it isn't so.  You force me to 
write so much extra code unless this functionality exists in the core.


Explain to me how every possible thing you might want to do to an array 
gets it's own function in the language, but something as trivial as this 
gets refused so strongly!


I mean really: array_change_key_case, array_chunk, array_combine, 
array_count_values, array_diff_assoc, array_diff_key, array_diff_uassoc, ...

   http://www.php.net/manual/en/ref.array.php

You can't tell me that most if not all of these functions could not have 
been implemented in userspace?  I might use 10% of all the array 
functions, but I'd use 'coalesce' and 'filled' daily.

/soap box

Tell me at least this much.  Can these two functions be implemented as 
an extension? From what you know about PHP internals, does what WE want 
have to be a language construct?  If I can write coalesce() and filled() 
as extensions, I'll submit a new extension/patch.  Maybe it could join 
PECL and with popularity make it's way begrudgingly into the core?


Dante

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



Re: [PHP-DEV] Seeking 'coalesce' php internal function

2006-05-03 Thread D. Dante Lorenso

Rasmus Lerdorf wrote:

Not sure what you guys are talking about.  ?: is on the roadmap.
-Rasmus


Ok.  That has some signs of hope.  What is ?: exactly, though.  I 
searched '?:' and yeah, good luck with that in documentation.  It 
doesn't smell like it supports all the specifics that 'filled()' does.  
Am I supposed to do this:


   $value = $x ?: $y ?: $z ?: $default;

And no warnings will be thrown for $x, $y, and $z not existing?  Did you 
see my post about 'filled()'?


   http://news.php.net/php.internals/23132

Honestly, I'm happy to see '?:' because that's better than nothing, but 
I think filled() is more like empty() and would be a better 
implementation.  If you want to look at the language from a consistency 
point of view '?:' is very PERL-like whereas filled(...) is PHP-like:


PERL-like:

   $x ~= s/\s+//;
   $x = $a ?: $b ?: $c;

PHP-like:
 
   $x = preg_replace(/\s+/, , $x);

   $x = filled($a, $b, $c);

In my PHP zen world, empty() and filled() are friends.  Ok, I've been 
selling 'filled()' for a while now.  Can we reverse the sell and try 
this .. why SHOULDN'T filled() be added to the language?


Dante

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



[PHP-DEV] Seeking 'coalesce' php internal function

2006-05-02 Thread D. Dante Lorenso

All,

I'm sure this has been asked somewhere, but since I see requests for 
features for 5.2 or 6.0, I'd like to add a simple item to the list 
which would be quite useful to me and would simplify and clean up a lot 
of code out there:


   function coalesce(...)

This works much like in the SQL version of the same.  In SQL, the 
function returns the first non-null argument from an arbitrary list.  In 
our use, it should return the first non-empty value from the list:


Example:

   $x = dante;
   $y = ;
   $z = ;

   $value = coalesce($z, $y, $x); // $value = dante

This function would ideally be built into the language and bypass 
warnings about undefined variables like 'empty' does.  It might be nice 
to have several varieties of this function:


   * return first parameter where empty() is FALSE
   * return first parameter where isset() is TRUE

I don't think something like this can NOT be written in userspace 
because the 'isset' and 'empty' checks need to be run before arguments 
can be passed to a user function or warnings will start flying.  A 
function like this simplifies code which used to look like this:


   if (!empty($_POST[postkey])) {
   $value = $_POST[postkey];
   }
   elseif (!empty($_GET[getkey])) {
   $value = $_POST[getkey];
   }
   elseif (!empty($default_value)) {
   $value = $default_value;
   }
   else {
   $value = hard coded value;
   }

Into this:

   $value = coalesce($_POST[postkey], $_GET[getkey], 
$default_value, hard coded value);


Can this be built and included?

Dante

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



[PHP-DEV] Request for Threads or SRM

2005-11-24 Thread D. Dante Lorenso

All,

I have been trying to use PHP 5.0.5 for all my programming tasks 
including replacing many stand-alone Java servers.  I've been successful 
to a degree, but I'm seriously missing Java Threads.  I've written some 
code which uses SHM, Sockets, IPC, and PCNTL, but it's not as clean and 
robust as it should be.


Since the jury is still deliberating over PHP6 and what it will offer, 
I'd like to put in my request to have a native PHP Thread object.  If 
Threads are too much to tackle, it would be nice to have something like 
SRM (Script Running Machine) which could be used for CLI environment 
stand-alone servers.


-- D. Dante Lorenso

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