Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Developing PHP Extensions with C++ and PHP-CPP: Advanced
Jan 08, 2015 @ 17:17:47

On the SitePoint PHP blog today Taylor Ren continues his look at using the PHP-CPP library to help build custom extensions. In this latest post he sheds some light on some more advanced topics.

In my earlier articles, I have introduced the PHP-CPP lib to create an extension for PHP using C++ (first article and second article). In the latter, I demonstrated a bit of the OO side of writing a PHP extension with a Complex class doing complex number manipulations. That introduction is not complete as the main focus of that article is more on the demonstration of the OO capability of PHP-CPP, not on the OO implementation details. In this article, we will further drill down the Complex lib development, adding more member functions, and addressing some advanced topics in writing a PHP extension with OO features using PHP-CPP

He breaks up the advanced topics into sections, providing code examples for each:

  • Returning this pointer in C++
  • Returning a Complex object pointer
  • Exposing the __toString magical method
  • Chaining member function calls
  • Exception throwing and handling in PHP

With the code in place, he then shows how to test all of the new functions you've added with a bit of simple PHP code.

tagged: tutorial advanced extension cplusplus phpcpp series part3

Link: http://www.sitepoint.com/developing-php-extensions-c-php-cpp-advanced/

Zend Developer Zone:
Wrapping C++ Classes in a PHP Extension
Apr 23, 2009 @ 15:21:50

On the Zend Developer Zone a new tutorial has been posted looking at taking your pre-existing C++ functionality and wrapping it in a PHP extension to be used directly in your code.

In this tutorial I am going to walk you through creating a PHP extension called "vehicles" which will expose a single class called "Car" (obviously in the real-world, your extensions will expose many classes, but I’m trying to keep things simple). The extension will be built for PHP 5. I am only going to give instructions for building the extension in a UNIX-like environment, although most of what I cover should apply to Windows extension development as well.

The tutorial walks you through everything - how the file layout should look, making a build system, the contents of his files (the sample extension lets you do things to the Car like shift gears and brake) and how to combine the C++ code with the build process to create a shared module you can include right in your php.ini.

tagged: module shared phpize buildfile tutorial c extension cplusplus class

Link:


Trending Topics: