Coding PHP extensions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suvarna271
    New Member
    • Feb 2013
    • 19

    Coding PHP extensions

    I am following "Extending and Embedding PHP" by Sara Golemon. While explaining the concepts she has used several small snippets of code as such

    Code:
    void describe_zval(zval *foo)
    {
        if (Z_TYPE_P(foo) == IS_NULL) {
            php_printf("The variable is NULL");
        } else {
            php_printf("The variable is of type %d",
                                Z_TYPE_P(foo));
        }
    }
    I tried writing the code in a .c file. But i am at loss regarding the dependencies required to compile the code.
    Please guide.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The quickest thing here is to research how a C/C++ program is built.

    Each .c file is compiled separately into a .obj file. Things like Z_TYPE and IS_NULL have to be declared before you can use them. You will need to #include a header file with those declarations.

    Then each .obj file is copied to the .exe file and missing definitions must be resolved. The actual code for things like Z_TYPE must be in another .obj file or in a library.

    This whole process is cotained in a file called a makefile.

    The steps to do this should be part of your IDE.

    Comment

    • suvarna271
      New Member
      • Feb 2013
      • 19

      #3
      Thanks @weaknessforcat s. Actually i was confused regarding the location of the macros Z_TYPE etc . Those are Zend variables and using phpize, just like its done for PHP extension development does the trick.

      Comment

      Working...