# Need help in defining a class from C code.

- Thread: https://externals.io/message/21684
- Original archive: https://news-web.php.net/php.internals/21684
- Started by Kiput on 2006-01-25T14:31:07+00:00
- Messages: 7
- 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

---

## #21684 — Kiput — 2006-01-25T14:31:07+00:00

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

Hi.

I'm currently working on a tiny "wrapper" in C++ which will aid in
easy embeding PHP in C++ apps. Till now I managed to work on it
without any help, but this time I need your help guys - I'm tired of
that messy, undocumented PHP/Zend code. Could anyone (I'm sure it's 5
minutes of work, since most of you work with PHP/Zend frequently)
write me a snippet of code in C which would be equal to following PHP
code:

class Foobar
{
    function __set( $name, $value )
    {
        echo( "$name = $value" );
    }
    function __get( $name )
    {
        echo( "$name" );
    }
}

I was working, but since I've implemented resource zval type into my
lib it somehow (I even didn't noticed) stopped. =(

If this is wrong list then I'm sorry, thought my question is closely
tied to PHP's internals after all. =)

Thanks.

---

## #21688 — Jeremy Johnstone — 2006-01-26T18:55:55+00:00

URL: https://externals.io/message/21684#21688 · In reply to: #21684

Kiput,

Even if you are right about the state of the PHP/Zend code/documentation
(which I am not commenting on either way), it's definitely not a wise idea
to insult the very people who wrote that code when asking for their
assistance. With that said, if no one else steps up with a code snippet
before I get home this evening, I would be happy to provide you with one.

-Jeremy


>
> Hi.
>
> I'm currently working on a tiny "wrapper" in C++ which will aid in
> easy embeding PHP in C++ apps. Till now I managed to work on it
> without any help, but this time I need your help guys - I'm tired of
> that messy, undocumented PHP/Zend code. Could anyone (I'm sure it's 5
> minutes of work, since most of you work with PHP/Zend frequently)
> write me a snippet of code in C which would be equal to following PHP
> code:
>
> class Foobar
> {
>     function __set( $name, $value )
>     {
>         echo( "$name = $value" );
>     }
>     function __get( $name )
>     {
>         echo( "$name" );
>     }
> }
>
> I was working, but since I've implemented resource zval type into my
> lib it somehow (I even didn't noticed) stopped. =(
>
> If this is wrong list then I'm sorry, thought my question is closely
> tied to PHP's internals after all. =)
>
> Thanks.
>
> --
> 
> 
>
>


--
---------------------------
Jeremy Johnstone
http://www.jeremyjohnstone.com
jsjohnst@php.net

---

## #21689 — Marcus Boerger — 2006-01-26T19:30:29+00:00

URL: https://externals.io/message/21684#21689 · In reply to: #21684

Hello Kiput,

  look into ext/spl/spl_array.c or here: http://talks.somabo.de

  & nobody stops you from making it less messy if you think it is, this is
  all open source.

Wednesday, January 25, 2006, 3:31:07 PM, you wrote:

> Hi.

> I'm currently working on a tiny "wrapper" in C++ which will aid in
> easy embeding PHP in C++ apps. Till now I managed to work on it
> without any help, but this time I need your help guys - I'm tired of
> that messy, undocumented PHP/Zend code. Could anyone (I'm sure it's 5
> minutes of work, since most of you work with PHP/Zend frequently)
> write me a snippet of code in C which would be equal to following PHP
> code:

> class Foobar
> {
>     function __set( $name, $value )
>     {
>         echo( "$name = $value" );
>     }
>     function __get( $name )
>     {
>         echo( "$name" );
>     }
> }

> I was working, but since I've implemented resource zval type into my
> lib it somehow (I even didn't noticed) stopped. =(

> If this is wrong list then I'm sorry, thought my question is closely
> tied to PHP's internals after all. =)

> Thanks.




Best regards,
 Marcus

---

## #21691 — Kiput — 2006-01-26T22:30:17+00:00

URL: https://externals.io/message/21684#21691 · In reply to: #21688

Hi.

Sorry, I didn't mean to insult anyone here. I love PHP, but it's
internals are undocumented, and are really hard to work with for
someone without prior experience. That's why I'm writing this wrapper
- to make it easy to embed PHP into other apps. It's a shame that no
one wrote something like this before. Anyway, I'll probably release it
later on sf.net with "do whatever you want, just leave copyright"
style license.

Thanks. =)

(Jeremy, I'm sorry for the double send, first message didn't have an
CC to php-internals. Hope you won't mind. =))

---

## #21692 — Marcus Boerger — 2006-01-26T22:51:30+00:00

URL: https://externals.io/message/21684#21692 · In reply to: #21691

Hello Kiput,

Why not put it in pecl under the php license or that copyright only thing?

Thursday, January 26, 2006, 11:30:17 PM, you wrote:

> Hi.

> Sorry, I didn't mean to insult anyone here. I love PHP, but it's
> internals are undocumented, and are really hard to work with for
> someone without prior experience. That's why I'm writing this wrapper
> - to make it easy to embed PHP into other apps. It's a shame that no
> one wrote something like this before. Anyway, I'll probably release it
> later on sf.net with "do whatever you want, just leave copyright"
> style license.

> Thanks. =)

> (Jeremy, I'm sorry for the double send, first message didn't have an
> CC to php-internals. Hope you won't mind. =))




Best regards,
 Marcus

---

## #21693 — Sara Golemon — 2006-01-26T23:16:35+00:00

URL: https://externals.io/message/21684#21693 · In reply to: #21684

> I'm currently working on a tiny "wrapper"
> in C++ which will aid in easy embeding PHP
> in C++ apps.
>
What functionality is it that you feel is lacking from sapi/embed?  I know
that C != C++, but C++ can certainly link against C libraries and using
sapi/embed is pretty well dirt-simple.  Or were you planning on dumbing it
down to the point where the C++ developer doesn't need to know what zval*
is, let alone how to interact with script code.

> Could anyone (I'm sure it's 5
> minutes of work, since most of you work with
> PHP/Zend frequently) write me a snippet of
> code in C which would be equal to following
> PHP code:
>
That depends very largely on whether or not you want it to be PHP4
compatable.  The structure is similar enough that PHP4 classes will work in
PHP5, but if you're willing to eschew PHP4 support, it'd be best to go with
a clean PHP5 design....

Wait.... are you planning on giving your PHP scripts direct access to your
C++ object instances?  Thats.... daring...

-Sara

---

## #21701 — Kiput — 2006-01-27T09:45:59+00:00

URL: https://externals.io/message/21684#21701 · In reply to: #21693

> What functionality is it that you feel is lacking from sapi/embed?  I know
> that C != C++, but C++ can certainly link against C libraries and using
> sapi/embed is pretty well dirt-simple.  Or were you planning on dumbing it
> down to the point where the C++ developer doesn't need to know what zval*
> is, let alone how to interact with script code.
Yes, I want to make it easy for someone who doesn't know anything
about how to handle core PHP/Zend code. Here is a litte sample of what
already can be done with it:

#include "php-cpp.h"

PHPCPP_FUNCTION( my_func )
{
    PHPCPP_CHECKARG( 1 );
    PHPCPP_VECTORIZE( Params );
    Params[ 0 ]++;

    PHPCPP_RETURN( Params[ 0 ] );
}

int main( )
{
    // Initialize, called once per app.
    Php :: Initialize( );

    Php :: AddFunctionEx( my_func );

    Php :: RequestStart( );
    {
        Php :: clZval A( 10 );
        Php :: clZval B( 20 );
        Php :: clZval C;

        C = A + B;
        Php :: SetGlobal( "foo", C );
        Php :: Interpret( "echo( my_func( $foo ) );" );
    }
    Php :: RequestEnd( );

    Php :: Destroy( );
}
(This code is untested, I've wrote it from memory =P)

> That depends very largely on whether or not you want it to be PHP4
> compatable.  The structure is similar enough that PHP4 classes will work in
> PHP5, but if you're willing to eschew PHP4 support, it'd be best to go with
> a clean PHP5 design....
I'm not aiming for PHP4. I even have this in my code:

#define PHPCPP_PHPVERSION ( `PHP_MAJOR_VERSION` * 10 + `PHP_MINOR_VERSION` )
#if PHPCPP_PHPVERSION < 51
    #error "Only PHP 5.1.0 and up is supported!"
#endif

> Wait.... are you planning on giving your PHP scripts direct access to your
> C++ object instances?  Thats.... daring...
Basically, yes. =)
