PhP4 the object of the detailed

Source: Internet
Author: User
Tags define definition class definition config php source code zend

The object of the PHP4

Once upon a time, in a very early version, PHP did not support any object-oriented programming syntax. The Zend Engine (ZE1) has been introduced in PhP4, and several new features have emerged, including the object data type.

Evolution of PHP Object types

The first object-oriented programming (OOP) support implements only the semantics of object associations. In the words of a PHP kernel developer, the PhP4 object simply binds an array and some methods together. It's the PHP object you're going to study now.

The second major release of the Zend Engine (ZE2) was in PHP5, introducing some new features into the OOP implementation of PHP. For example, properties and methods can use an access modifier to mark their visibility outside of your class definition, and the overload of a function can be used to define the custom behavior of the internal language structure, which can be standardized between the invocation chains of multiple classes using the interface implementation API. As you learn the 11th chapter "PHP5 Object", you will build awareness of this knowledge by implementing these features in the PHP5 class definition.

Implementation class

Before we enter the OOP world, we need to travel light. Therefore, restore your extension to the skeleton form just built in the 5th chapter "Your first extension".

To be independent of your original assignments, you can name this version sample2. Put the following three files into the Ext/sample2 directory of your PHP source code:

Config.m4

Php_arg_enable (Sample2,  
  [Whether to enable the "sample2" extension],  
  [  enable-sample2       Enable] Sample2 "extension support]"  
      
if test $PHP _sample2!= "No"; then Php_subst  
  (sample2_shared_libadd)  
  Php_new_ EXTENSION (Sample2, sample2.c, $ext _shared)  
fi

Php_saple2.h

#ifndef php_sample2_h/  
* Prevent double inclusion */
#define PHP_SAMPLE2_H/  
      
* Define Extension Properties * *
#define Php_sample2_extname    "Sample2"  
#define Php_sample2_extver    "1.0"/  
      
* Import Configure Options when 
   building outside to 
   the PHP source tree */
#ifdef have_config_h  
#include "config.h"  
#endif/  
      
* Include PHP Standard Header/
#include "php.h"/*  
      
Define The entry point symbol 
 * Zen D'll use when loading this module 
 *
/extern zend_module_entry sample2_module_entry;  
#define PHPEXT_SAMPLE2_PTR &sample2_module_entry  
      
#endif/* Php_sample2_h *

Sample2.c

#include "php_sample2.h"  
      
static function_entry php_sample2_functions[] = {  
    {null, NULL, NULL}  
};  
      
Php_minit_function (Sample2)  
{return  
    SUCCESS;  
}  
      
Zend_module_entry sample2_module_entry = {  
#if zend_module_api_no >= 20010901 standard_module_header  
    ,  
#endif  
    Php_sample2_extname,  
    php_sample2_functions,  
    php_minit (sample2),  
    null,/* Mshutdown */
    NULL,/* Rinit */
    NULL,/* Rshutdown/
    NULL,/* MINFO/
#if zend_module_api_no >=  
    20010901 php_sample2_ Extver,  
#endif  
    standard_module_properties  
};  
      
#ifdef compile_dl_sample2  
zend_get_module (sample2)  
#endif

Now, as in the 5th chapter, you can perform phpize,./configure, make to build your sample2.so extension module.

Your previous config.w32 do the same as the config.m4 here, and you can work properly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.