[PHP-DEV] ext/overload API

2002-11-14 Thread Timm Friebe
Hello,
Andrei, as I can see, you're the author of ext/overload. As suggested
earlier, I've added a second parameter to sybase_fetch_object() which
allows users to pass an object to be filled with the results from the
fetched row (e.g. $article= sybase_fetch_object($q, new Article()); or
$article= sybase_fetch_object($q, 'Article')).

Well, if Article is an overloaded class, they'd probably expect that
their __set*-handlers are called when the object's properties are set.
Of course, object_and_properties_init() does not do this. But indeed,
it'd be quite nice if they would.

Thus, one would need the C functions call_get_handler and
call_set_handler to be declared not static but PHPAPI (is this right?)
and an additional method to test if a zend_class_entry is overloaded.

* http://sitten-polizei.de/php/overload.patch
  would make it work. Maybe macros would be a better way?

* http://sitten-polizei.de/php/sybase_ct.patch
  shows a sample usage (btw, is there any documentation on TSRM?)
  maybe _set_object_prop should be moved to ext/overload as a 
  utiltiy function?

I came up with this since I use sybase resultsets within SOAP, clearly
needing to distinguish strings from datetime types, int, floats and so
on. My first idea was to introduce a function
sybase_bind_datatype(SYBASE_DATETIME, 'Date')
but why not make use of an already existing and powerful extension?

Maybe an example illustrates best what you'd be able to do:

Example
---
?php
  class Date {
var $_u;

function Date($m) {
  switch (gettype($m)) {
case 'string': $this-_u= strtotime($m); break;
case 'integer': $this-_u= $m; break;
  }
}

// [...]
  }

  class Article {
var $article_id, $caption, $text, $lastchange;

function __set($k, $v) {
  $this-$k= $v;
  return TRUE;
}

function __get($k) {
  return $this-$k;
}

function __set_lastchange($val) {
  $this-lastchange= new Date($val);
  return TRUE;
}

// [...]
  }

  overload('Article');

  // [...]
  $q= sybase_query(
'select article_id, caption, text, lastchange from article',
$dbh
  );
  while ($article= sybase_fetch_object($q, 'Article')) {
var_dump($article);
  }
  // [...]
?

Sample Output
-
object(article)(4) {
  [article_id]=
  int(6100)
  [caption]=
  string(7) Caption
  [text]=
  string(19) This is the text:-)
  [lastchange]=
  object(date)(1) {
[_u]=
int(1025458800)
  }
}

- Timm



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




Re: [PHP-DEV] ext/overload API

2002-11-14 Thread Andrei Zmievski
On Thu, 14 Nov 2002, Timm Friebe wrote:
 Hello,
 Andrei, as I can see, you're the author of ext/overload. As suggested
 earlier, I've added a second parameter to sybase_fetch_object() which
 allows users to pass an object to be filled with the results from the
 fetched row (e.g. $article= sybase_fetch_object($q, new Article()); or
 $article= sybase_fetch_object($q, 'Article')).
 
 Well, if Article is an overloaded class, they'd probably expect that
 their __set*-handlers are called when the object's properties are set.
 Of course, object_and_properties_init() does not do this. But indeed,
 it'd be quite nice if they would.
 
 Thus, one would need the C functions call_get_handler and
 call_set_handler to be declared not static but PHPAPI (is this right?)
 and an additional method to test if a zend_class_entry is overloaded.
 
 * http://sitten-polizei.de/php/overload.patch
   would make it work. Maybe macros would be a better way?
 
 * http://sitten-polizei.de/php/sybase_ct.patch
   shows a sample usage (btw, is there any documentation on TSRM?)
   maybe _set_object_prop should be moved to ext/overload as a 
   utiltiy function?
 
 I came up with this since I use sybase resultsets within SOAP, clearly
 needing to distinguish strings from datetime types, int, floats and so
 on. My first idea was to introduce a function
   sybase_bind_datatype(SYBASE_DATETIME, 'Date')
 but why not make use of an already existing and powerful extension?

Because this extension is going away in ZE2?

-Andrei   http://www.gravitonic.com/
* We reason deeply, when we forcibly feel. *

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




Re: [PHP-DEV] ext/overload API

2002-11-14 Thread Timm Friebe
On Thu, 2002-11-14 at 14:09, Timm Friebe wrote:
 Hello,
[...]
 function __get($k) {
   return $this-$k;
 }
[...]

Woops, this is wrong, of course.

function __get($k, $v) {
  $v= $this-$k;
  return TRUE;
}

I also missed that if a member variable exists, __get or __set won't be
called. I think this'd be quite useful though...

-- 
Timm
Any sufficiently advanced bug is indistinguishable from a feature


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