RE: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Derick Rethans
On Wed, 22 Oct 2003, Lukas Smith wrote:

> > I wouldn't mind such a change myself, however what about all the
> > installations
> > where people do while (*fetch_row() !== false) ?
> 
> Yeah ... php5 would be a good time to make this change.

Not really, this is just too much of a BC break to me.

> I don't assume that a lot of people will actually do !== since in those
> methods you either get an array or false ..

>From what I've seen this is used a lot...

Derick

-- 
"Interpreting what the GPL actually means is a job best left to those
that read the future by examining animal entrails."
-
 Derick Rethans http://derickrethans.nl/ 
 International PHP Magazine  http://php-mag.net/
-

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



Re: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Derick Rethans
On Wed, 22 Oct 2003, Ard Biesheuvel wrote:

> > Err .. I don't agree.
> > Null means no data
> > False means error.
> 
> Maybe historically (PHP-wise) it does.
> But the way I see it, every fetch() can 'fail' for two reasons: an 
> expected well-defined reason (eof), and an unexpected undefined reason 
> (error). Labelling the well-defined reason as 'false' and the undefined 
> reason as 'null' is really quite defendable.

I think so too, but I wonder how much this is going to break :)

Derick

-- 
"Interpreting what the GPL actually means is a job best left to those
that read the future by examining animal entrails."
-
 Derick Rethans http://derickrethans.nl/ 
 International PHP Magazine  http://php-mag.net/
-

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



Re: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Cesare D'Amico
Alle 00:18, giovedì 23 ottobre 2003, Lukas Smith ha scritto:
> run query that works
> run query that doesn't
>
> now when you fetch the rows of the first query you will usually
> determine if you hit the end if the result set by checking if you
> don't get an array returned
>
> if you don't get an array you check for an error and in several ext
> you will get the error created by the second query. This is also
> caused by the fact that the error checking simply returns the last
> error which cant be cleared appearently.

But can't you resolve this problem by checking if the query worked just 
after issuing it? I mean, do something like:

. run query 1
. check if q1 worked
. run query 2
. check if q2 worked
. if q1 worked -> fetch data

...and so on.

Perhaps I'm missing something, but I can't see a real issue here.

-- 
Cesare D'Amico - http://www.phpday.it
"E` un'emergenza!!! Dovrei fare questo-e-questaltro ma non 
posso perche' la mia testa e` piena di segatura e criceti!!!"
 -- un utente [ http://www.soft-land.org/storie/ ]

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



RE: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Lukas Smith
> From: Cesare D'Amico [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 23, 2003 2:59 PM

> Alle 00:18, giovedì 23 ottobre 2003, Lukas Smith ha scritto:
> > run query that works
> > run query that doesn't
> >
> > now when you fetch the rows of the first query you will usually
> > determine if you hit the end if the result set by checking if you
> > don't get an array returned
> >
> > if you don't get an array you check for an error and in several ext
> > you will get the error created by the second query. This is also
> > caused by the fact that the error checking simply returns the last
> > error which cant be cleared appearently.
> 
> But can't you resolve this problem by checking if the query worked just
> after issuing it? I mean, do something like:
> 
> . run query 1
> . check if q1 worked
> . run query 2
> . check if q2 worked
> . if q1 worked -> fetch data
> 
> ...and so on.
> 
> Perhaps I'm missing something, but I can't see a real issue here.

Yeah, you are missing something :-/

mysql_error() will return you the last error over and over again.

So you find that q2 didn’t work and you want to proceed then you will from
then on always get that failure from q2 until you produce a new error. This
is not the case in all ext but iirc atleast in mssql and sybase the problem
also seems to exist.

While I think about it: There would be one solution that wouldn’t break BC:
adding a function that would clear the last error. Then you could manually
clear an error after you have read it.

The other alternative would be to remember the last error and check if that
error is the same every time you check and all such solutions are possible
but very hacky of course.

Regards,
Lukas

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



Re: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Cesare D'Amico
Alle 15:02, giovedì 23 ottobre 2003, Lukas Smith ha scritto:
> > . run query 1
> > . check if q1 worked
> > . run query 2
> > . check if q2 worked
> > . if q1 worked -> fetch data
> >
> > ...and so on.
> >
> > Perhaps I'm missing something, but I can't see a real issue here.
>
> Yeah, you are missing something :-/

[...]

> The other alternative would be to remember the last error and check
> if that error is the same every time you check and all such solutions
> are possible but very hacky of course.

Well, I didn't miss anything :)

What you call hacky is the way I usually work: do something, check if 
there was an error; if so, collect the error, else (or then) go on.

I don't want to be polemical, only I can't see anything wrong (if you 
need the mysql_error()) in doing something like:

. run query 1
. check if q1 worked
. if not -> q1_error = mysql_error()
. run query 2
. check if q2 worked
. if not -> q2_error = mysql_error()
. if q1 worked -> fetch data

It's obvious that I am no-one in the php decisional process ;)
I think that your proposal would be more elegant than the way things are 
now; it would be also better, if it didn't break bc with ways of 
programming that are commonly in use.

Again: no polemical spirit :)

Ciao
 ce
-- 
Cesare D'Amico - http://www.phpday.it
"E` un'emergenza!!! Dovrei fare questo-e-questaltro ma non 
posso perche' la mia testa e` piena di segatura e criceti!!!"
 -- un utente [ http://www.soft-land.org/storie/ ]

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



RE: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Lukas Smith
> From: Cesare D'Amico [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 23, 2003 3:27 PM
> 
> Alle 15:02, giovedì 23 ottobre 2003, Lukas Smith ha scritto:
> > > . run query 1
> > > . check if q1 worked
> > > . run query 2
> > > . check if q2 worked
> > > . if q1 worked -> fetch data
> > >
> > > ...and so on.
> > >
> > > Perhaps I'm missing something, but I can't see a real issue here.
> >
> > Yeah, you are missing something :-/
> 
> [...]
> 
> > The other alternative would be to remember the last error and check
> > if that error is the same every time you check and all such solutions
> > are possible but very hacky of course.
> 
> Well, I didn't miss anything :)
> 
> What you call hacky is the way I usually work: do something, check if
> there was an error; if so, collect the error, else (or then) go on.

Well errors are not always fatal .. and if they are not then it should be
possible to proceed without any further "harm" to your script.

For example in the sequence emulation in PEAR::DB you can optionally created
sequences on demand. This is done if the query to select the next value
failed with an error specifying that sequence does not exist. We currently
just trap that error and if the user wants we create the sequence for him
and everything should proceed as usual. However this doesn’t work if we also
check for errors during fetching (unless we know the end of the result set
.. which you obviously could do with a counter and a call to
mysql_num_rows() unless of course you are doing an unuffered query). So
anyways the current situation is very messy. A fix to atleast let us do the
error checking would be to have a mysql_clear_error() or something like
that.

Anyways nuff said about this issue. :-)

Regards,
Lukas

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



Re: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Dirkjan Ochtman
> While I think about it: There would be one solution that wouldn't break
BC:
> adding a function that would clear the last error. Then you could manually
> clear an error after you have read it.

I could see that mysql_reset_error() would be useful. + 1!

Regards,

Manuzhai

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



Re: [PHP-DEV] Proposal: Dangling comma in function call parameters

2003-10-23 Thread Christian Schneider
Andi Gutmans wrote:
In this case I don't see the same advantage and I see a disadvantage in 
readability and the possibility for PHP to give such an empty argument a 
meaning in future (although I doubt that'll happen).
Ok, here the real-world example from our HTML generation toolkit:
table(
tr(td('row 1 cell 1'), td('row 1 cell 2')),
tr(td('row 2 cell 1'), td('row 2 cell 2')),
);
Being able to easily append lines here would be really nice :-)
It doesn't break existing things _and_ it's up to the programmer to use 
this feature, same as in array().

I was also thinking of proposing named parameters, i.e. basically 
removing the need for array() in foo(array('style' => 'hot', 'size' => 
42)); but I guess that'll be even more controversial :-)

Ok, that's it from my side, it's up to you now,
- Chris
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DEV] database driver: no more rows

2003-10-23 Thread Andi Gutmans
At 03:02 PM 10/23/2003 +0200, Lukas Smith wrote:

mysql_error() will return you the last error over and over again.
Shouldn't the mysql extension clear the last error on a successful query?

Andi

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


RE: [PHP-DEV] database driver: no more rows

2003-10-23 Thread David Gillies
I use syntax like
while(($dbrow=mysql_fetch_assoc($dbresult))!==false)
in several hundred locations in a production ap. If
PHP breaks my code then it won't get used. Simple as
that.

Anyway, unless I'm missing something, isn't the
preferred PHP5 way to handle this via exceptions?
Certainly the mysql driver is in error if it doesn't
either a) reset the error after a successful call or
b) distinguish between 'done' and 'failed' (like unix
read() returning 0 is not an error, but -1 is).
However a cleaner way of doing it for genuinely new
code which would maintain BC would be for the driver
writers to make it throw an exception, which would be
disabled by default. Just a thought.

Best Wishes
David Gillies
San Jose
Costa Rica

--- Lukas Smith <[EMAIL PROTECTED]> wrote:
> > From: Ilia Alshanetsky [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, October 22, 2003 7:18 PM
> > To: Lukas Smith; 'PHP Development'
> > Subject: Re: [PHP-DEV] database driver: no more
> rows
> > 
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
> > 
> > I wouldn't mind such a change myself, however what
> about all the
> > installations
> > where people do while (*fetch_row() !== false) ?
> 
> Yeah ... php5 would be a good time to make this
> change.
> I don't assume that a lot of people will actually do
> !== since in those
> methods you either get an array or false ..
> 
> Regards,
> Lukas
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



[PHP-DEV] [PATCH] Memory corruption when freeing an object zval twice

2003-10-23 Thread Vesselin Atanasov
Hello.
There is a bug in PHP5 code which shows when an object destructor tries to access the 
zval for the object being destroyed. Here is a
sample code:


What happens is that upon program shutdown the symtable is cleared the
refcount for gA zval goes to zero and the zval destructor is called.
It calls the zend_objects_destroy_object() function which has following
code:

...
ZEND_INIT_SYMTABLE(&symbol_table);

/* FIXME: Optimize this so that we use the old_object->ce->destructor 
function pointer instead of the name */
MAKE_STD_ZVAL(destructor_func_name);
destructor_func_name->type = IS_STRING;
destructor_func_name->value.str.val = estrndup("__destruct", 
sizeof("__destruct")-1);
destructor_func_name->value.str.len = sizeof("__destruct")-1;

call_user_function_ex(NULL, &obj, destructor_func_name, &retval_ptr, 
0, NULL, 0, &symbol_table TSRMLS_CC);

zend_hash_destroy(&symbol_table);
...

this code sets a temporary symtable and calls the A::__destruct. When the __destruct 
functions
accesses the gA object via "global $gA" its refcount goes from 0 to 1 and after return 
from
"__destruct" the "zend_hash_destroy(&symbol_table);" line kills the symtable, and the 
zval
refcount goes to zero again, this causes the zval structure to be freed, and then it 
is freed
once again on return from zend_objects_destroy_object(), thus causing memory 
corruption.
Here is a patch that fixes the problem:

diff -ruN php5-200310182330.orig/Zend/zend_variables.c 
php5-200310182330/Zend/zend_variables.c
--- php5-200310182330.orig/Zend/zend_variables.c2003-08-24 18:06:54.0 
+
+++ php5-200310182330/Zend/zend_variables.c 2003-10-23 19:09:11.0 +
@@ -58,7 +58,14 @@
{
TSRMLS_FETCH();

+   /* Increase temporarily the object zvalue refcount in 
order to protect
+   the object zvalue from being destroyed one more time 
if it is accessed
+   from the object destructor call chain. This could 
happen if the
+   object destructor accesses the object as a global 
variable by name. */
+
+   zvalue->refcount++;
Z_OBJ_HT_P(zvalue)->del_ref(zvalue TSRMLS_CC);
+   zvalue->refcount--;
}
break;
case IS_RESOURCE:

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



Re: [PHP-DEV] overload extension

2003-10-23 Thread LingWitt
This may be where the problem:

zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args);

Would this do the trick?

zend_get_parameters_array(ZEND_NUM_ARGS(), args);

On Wednesday, Oct 22, 2003, at 20:47 America/New_York, Alan Knowles 
wrote:

There is already a bug report on it, however It sounds like it's 
unlikely to be fixed in PHP4...

Regards
Alan
[EMAIL PROTECTED] wrote:
The methods of an object that has been passed to the overload() 
function lose their ability to have parameters passed by reference. 
For example:
class Foo
{
function hello(&$array)
{
$array[] = "hello";
}
}
$array = null;
$foo = & new foo();
$foo->hello($array);
print_r($array)
Output:
Array
(
[0] => hello
)
class Foo extends PEAR_Autoloader
{
function hello(&$array)
{
$array[] = "hello";
}
}
$array = null;
$foo = & new foo();
$foo->hello($array);
print_r($array)
Output:
Nothing!


--
Can you help out?
Need Consulting Services or Know of a Job?
http://www.akbkhome.com
--
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] Re: named function arguments (was: Proposal: Dangling comma in function call parameters)

2003-10-23 Thread netcat
Christian Schneider wrote:

[snip]

I was also thinking of proposing named parameters, i.e. basically 
removing the need for array() in foo(array('style' => 'hot', 'size' => 
42)); but I guess that'll be even more controversial :-) 
Named parameters - i think is very good idea. I know i would use them.
I'm really not sure about the correct syntax for it though.
They should be optional and may have default values
and provide a way to extend old functions that
already have optional parameters.
Just for example:
function f($a,$b=false,keyword $c='xyz') {
}
f(1)
f(1,true)
f(1,c='www')
f(1,true,c='www')
Just general thoughts:
Maybe there should be a way to specify that
a keyword is required.
Maybe there should be a way to specify external
name other than argument variable name as in the
following example:
function g($a,keyword 'aa' $ab) {
}


Ok, that's it from my side, it's up to you now,
- Chris


--
NetCat


--
SPAM-Free 10mb Free email + Antivirus + POP3 + more...
Get it at http://www.doal.co.il:81/free/?c=all-spam
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DEV] Re: named function arguments

2003-10-23 Thread Christian Schneider
netcat wrote:
Named parameters - i think is very good idea. I know i would use them.
I'm really not sure about the correct syntax for it though.
Important for our application would be that it works with varargs, as we 
have a lot of (potential) parameters of which you normally only give a 
small subset. And having a huge parameter list with default values just 
doesn't do it there. We're using one associative array as parameter for 
this purpose right now.

- Chris

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


Re: [PHP-DEV] Re: named function arguments

2003-10-23 Thread Sebastian Bergmann
netcat wrote:
> Named parameters - i think is very good idea.

  Named parameters are commonly implemented using an associated array in
  PHP:

 'bar',
'bar' => 'foo'
  )
);
?>

-- 
Sebastian Bergmann
http://sebastian-bergmann.de/   http://phpOpenTracker.de/

Das Buch zu PHP 5: http://professionelle-softwareentwicklung-mit-php5.de/

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