# Extension DLL Objects

- Thread: https://externals.io/message/14941
- Original archive: https://news-web.php.net/php.internals/14941
- Started by Chris Cranford on 2005-02-14T23:40:29+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #14941 — Chris Cranford — 2005-02-14T23:40:29+00:00

URL: https://externals.io/message/14941#14941

I want to have a function that returns an object that essentially looks like
the following:

$user->name; // string that holds name of user
$user->from; // string that holds where user is from
$user->update(); // method that updates changed user data to db (**unsure
how to code this)

In my php script, I have defined a function "getuser" I call that returns
this object.
Here is a sample from my script:

<?php
  $user = getuser();
  echo "Your username is ".$user->name." from ".$user->from;
  $user->from = "Nowhereville, USA";
  $user->update(); // updates user record and saves to db
?>

Is there any specific or standard way I should be creating this object?
Right now my code looks like this:

  ZEND_FUNCTION(getuser) {
    TUser u;
    if(GetLoggedInUser(&u)) {
      if(object_init(return_value)==SUCCESS) {
        add_property_string(return_value,"name",u.Info.Name,1);
        add_property_string(return_value,"from",u.From,1);
        // need to add a reference to the update function here ??
        // unclear how to do this.
        return;
      }
    }
    RETURN_NULL();
  }

And how do I go about adding that "update()" function to my object to handle
a function
call to commit the object changes to the database?

Thanks
Chris

---

## #14950 — Alan Knowles — 2005-02-15T02:09:15+00:00

URL: https://externals.io/message/14941#14950 · In reply to: #14941

have a look at dbdo in cvs.php.net/pecl/dbdo, or look at the source for
the midgard php extension, both of them do this.

Regards
Alan


> I want to have a function that returns an object that essentially looks like
> the following:
> 
> $user->name; // string that holds name of user
> $user->from; // string that holds where user is from
> $user->update(); // method that updates changed user data to db (**unsure
> how to code this)
> 
> In my php script, I have defined a function "getuser" I call that returns
> this object.
> Here is a sample from my script:
> 
> <?php
>   $user = getuser();
>   echo "Your username is ".$user->name." from ".$user->from;
>   $user->from = "Nowhereville, USA";
>   $user->update(); // updates user record and saves to db
> ?>
> 
> Is there any specific or standard way I should be creating this object?
> Right now my code looks like this:
> 
>   ZEND_FUNCTION(getuser) {
>     TUser u;
>     if(GetLoggedInUser(&u)) {
>       if(object_init(return_value)==SUCCESS) {
>         add_property_string(return_value,"name",u.Info.Name,1);
>         add_property_string(return_value,"from",u.From,1);
>         // need to add a reference to the update function here ??
>         // unclear how to do this.
>         return;
>       }
>     }
>     RETURN_NULL();
>   }
> 
> And how do I go about adding that "update()" function to my object to handle
> a function
> call to commit the object changes to the database?
> 
> Thanks
> Chris
> 
-- 
Alan Knowles <alan@akbkhome.com

---

## #14951 — Chris Cranford — 2005-02-15T02:24:12+00:00

URL: https://externals.io/message/14941#14951 · In reply to: #14950

And I should also mention I'm trying to do this for PHPv4 and not v5.
I'm not sure if that affects how the coding is done or not as I'm
quite new to all this.

----- Original Message ----- 
From: "Alan Knowles" <alan@akbkhome.com>
To: "Chris Cranford" <chris.cranford@tkdsoftware.com>
Cc: <internals@lists.php.net>
Sent: Monday, February 14, 2005 9:09 PM
Subject: Re: [PHP-DEV] Extension DLL Objects


> have a look at dbdo in cvs.php.net/pecl/dbdo, or look at the source for
> the midgard php extension, both of them do this.
>
> Regards
> Alan
>
> 
> > […]
like
> > […]
(**unsure
> > […]
returns
> > […]
handle
> > […]
> -- 
> Alan Knowles <alan@akbkhome.com

---

## #14952 — Alan Knowles — 2005-02-15T02:38:26+00:00

URL: https://externals.io/message/14941#14952 · In reply to: #14951

Midgard code is probably the one to look at, but the object code in PHP5
is alot easier to work with.

Regards
Alan


> And I should also mention I'm trying to do this for PHPv4 and not v5.
> I'm not sure if that affects how the coding is done or not as I'm
> quite new to all this.
> 
> ----- Original Message ----- 
> From: "Alan Knowles" <alan@akbkhome.com>
> To: "Chris Cranford" <chris.cranford@tkdsoftware.com>
> Cc: <internals@lists.php.net>
> Sent: Monday, February 14, 2005 9:09 PM
> Subject: Re: [PHP-DEV] Extension DLL Objects
> 
> 
> > […]
> like
> > […]
> (**unsure
> > […]
> returns
> > […]
> handle
> > […]
> 
-- 
Alan Knowles <alan@akbkhome.com
