c++ with PHP

General discussions related to php

Moderators: macek, egami, gesf

devendraC
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Aug 19, 2003 1:57 am

c++ with PHP

Postby devendraC » Tue Aug 19, 2003 2:26 am

Hi,
I am using c++ with php 4.3.2.
My problem is that objects created in one page can not be used in another page.

The detail of problem is as:
In first page I create object like this:

<?
session_start();
session_register("object");
$object = myphpclass();
$object->setstring("Hello how are you");
echo "<br>",$object->getstring(), "<br>";
?>
which is working fine.
(here myphpclass is created in c++).


Now when I use $object in another page like this:
<?
session_start();
$obj=$_SESSION['object'];
$obj->getstring()
?>
Following error come:
Fatal error: underlying object is of wrong type in getstring().


Please help

Regards
Devendra

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Tue Aug 19, 2003 3:26 am

I think this may help you
http://bugs.tutorbuddy.com/phpcpp/phpcp ... _code.html
check this out !

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: c++ with PHP

Postby swirlee » Tue Aug 19, 2003 6:33 am

devendraC wrote:I am using c++ with php 4.3.2.


Um. I think you might be more than just a little bit confused. You might be using OOP, or Object-Oriented Programming, but unless the link that sigix posted makes sense to you, you aren't using C++. You see, C++ is a programming language, a superset of the C programming language. It happens to be object-oriented, but creating objects and classes in PHP is not "using C++". In other words, you're not using C++. You're using OOP, or the object model, or classes and objects, or however you care to describe it. But you aren't using C++, which is something completely unrelated (fundamentally speaking) to PHP.

Anyway, your problem is likely that you aren't including your class definition in the second file. To quote a comment in the documentation:

shanemayer42 at yahoo dot com
19-Aug-2000 05:11

When putting objects in a session, you need to have declared the class of your session managed objects BEFORE they are restored with a session_register or equivalent call.

That means before the session_start()!


In other words, you need your class definition to be included in both files (both the originating page and the page on which you're attempting to restore the object), and in the second file, it must appear before the line on which you try to restore the object.

devendraC
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Aug 19, 2003 1:57 am

Postby devendraC » Tue Aug 19, 2003 9:21 pm

Hi All,
Thanks for reply.
Actually my program is inspired by the article given in link:
http://bugs.tutorbuddy.com/phpcpp/phpcp ... _code.html

I am using c++ libraries for creating objects in php. The problem is when we create C++ objects in the shared library through php code, and need them to be persistent across web pages or in a session. How can I acheive this as PHP does this by serializing the objects to a file, which is not a good enough approach in my case.

Also can anyone help me locate the details or documentation of functions used while creating extensions for PHP (ZEND_REGISTER_RESOURCE, zend_hash_update, and the likes)

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Wed Aug 20, 2003 7:03 am

devendraC wrote:I am using c++ libraries for creating objects in php.


Ah. My mistake.

sigix
php-forum Active User
php-forum Active User
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby sigix » Wed Aug 20, 2003 10:01 pm

you can find all ZEND_* functions from official zend site... :arrow:


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests