LTP GCOV extension - code coverage report
Current view: directory - ext/standard - incomplete_class.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 62
Code covered: 17.7 % Executed lines: 11
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2007 The PHP Group                                |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 3.01 of the PHP license,      |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.php.net/license/3_01.txt                                  |
      11                 :    | If you did not receive a copy of the PHP license and are unable to   |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@php.net so we can mail you a copy immediately.               |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Author:  Sascha Schumann <sascha@schumann.cx>                        |
      16                 :    +----------------------------------------------------------------------+
      17                 :  */
      18                 : 
      19                 : 
      20                 : /* $Id: incomplete_class.c,v 1.28.2.2.2.2 2007/02/01 14:07:43 tony2001 Exp $ */
      21                 : 
      22                 : #include "php.h"
      23                 : #include "basic_functions.h"
      24                 : #include "php_incomplete_class.h"
      25                 : 
      26                 : #define INCOMPLETE_CLASS_MSG \
      27                 :                 "The script tried to execute a method or "  \
      28                 :                 "access a property of an incomplete object. " \
      29                 :                 "Please ensure that the class definition \"%s\" of the object " \
      30                 :                 "you are trying to operate on was loaded _before_ " \
      31                 :                 "unserialize() gets called or provide a __autoload() function " \
      32                 :                 "to load the class definition "
      33                 : 
      34                 : 
      35                 : static zend_object_handlers php_incomplete_object_handlers;
      36                 : 
      37                 : /* {{{ incomplete_class_message
      38                 :  */
      39                 : static void incomplete_class_message(zval *object, int error_type TSRMLS_DC)
      40               0 : {
      41                 :         char *class_name;
      42               0 :         zend_bool class_name_alloced = 1;
      43                 : 
      44               0 :         class_name = php_lookup_class_name(object, NULL);
      45                 :         
      46               0 :         if (!class_name) {
      47               0 :                 class_name_alloced = 0;
      48               0 :                 class_name = "unknown";
      49                 :         }
      50                 :         
      51               0 :         php_error_docref(NULL TSRMLS_CC, error_type, INCOMPLETE_CLASS_MSG, class_name);
      52                 : 
      53               0 :         if (class_name_alloced) {
      54               0 :                 efree(class_name);
      55                 :         }
      56               0 : }
      57                 : /* }}} */
      58                 : 
      59                 : static zval *incomplete_class_get_property(zval *object, zval *member, int type TSRMLS_DC)
      60               0 : {
      61               0 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      62               0 :         if(type == BP_VAR_W || type == BP_VAR_RW) {
      63               0 :                 return EG(error_zval_ptr);
      64                 :         } else {
      65               0 :                 return EG(uninitialized_zval_ptr);
      66                 :         }
      67                 : }
      68                 : 
      69                 : static void incomplete_class_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
      70               0 : {
      71               0 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      72               0 : }
      73                 :         
      74                 : static zval **incomplete_class_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC)
      75               0 : {
      76               0 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      77               0 :         return &EG(error_zval_ptr);
      78                 : }
      79                 : 
      80                 : static void incomplete_class_unset_property(zval *object, zval *member TSRMLS_DC)
      81               0 : {
      82               0 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      83               0 : }
      84                 : 
      85                 : static int incomplete_class_has_property(zval *object, zval *member, int check_empty TSRMLS_DC)
      86               0 : {
      87               0 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      88               0 :         return 0;
      89                 : }
      90                 : 
      91               0 : static union _zend_function *incomplete_class_get_method(zval **object, char *method, int method_len TSRMLS_DC) {
      92               0 :         incomplete_class_message(*object, E_ERROR TSRMLS_CC);
      93               0 :         return NULL;
      94                 : }
      95                 : 
      96                 : /* {{{ php_create_incomplete_class
      97                 :  */
      98               0 : static zend_object_value php_create_incomplete_object(zend_class_entry *class_type TSRMLS_DC) {
      99                 :         zend_object *object;
     100                 :         zend_object_value value;
     101                 :         
     102               0 :         value = zend_objects_new(&object, class_type TSRMLS_CC);
     103               0 :         value.handlers = &php_incomplete_object_handlers;
     104                 :         
     105               0 :         ALLOC_HASHTABLE(object->properties);
     106               0 :         zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
     107               0 :         return value;
     108                 : }
     109                 : 
     110                 : zend_class_entry *php_create_incomplete_class(TSRMLS_D)
     111             220 : {
     112                 :         zend_class_entry incomplete_class;
     113                 : 
     114             220 :         INIT_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL);
     115             220 :         incomplete_class.create_object = php_create_incomplete_object;
     116                 : 
     117             220 :         memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
     118             220 :         php_incomplete_object_handlers.read_property = incomplete_class_get_property;
     119             220 :         php_incomplete_object_handlers.has_property = incomplete_class_has_property;
     120             220 :         php_incomplete_object_handlers.unset_property = incomplete_class_unset_property;
     121             220 :         php_incomplete_object_handlers.write_property = incomplete_class_write_property;
     122             220 :         php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr;
     123             220 :     php_incomplete_object_handlers.get_method = incomplete_class_get_method;
     124                 :         
     125             220 :         return zend_register_internal_class(&incomplete_class TSRMLS_CC);
     126                 : }
     127                 : /* }}} */
     128                 : 
     129                 : /* {{{ php_lookup_class_name
     130                 :  */
     131                 : PHPAPI char *php_lookup_class_name(zval *object, zend_uint *nlen)
     132               0 : {
     133                 :         zval **val;
     134               0 :         char *retval = NULL;
     135                 :         HashTable *object_properties;
     136                 :         TSRMLS_FETCH();
     137                 : 
     138               0 :         object_properties = Z_OBJPROP_P(object);
     139                 : 
     140               0 :         if (zend_hash_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER), (void **) &val) == SUCCESS) {
     141               0 :                 retval = estrndup(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
     142                 : 
     143               0 :                 if (nlen)
     144               0 :                         *nlen = Z_STRLEN_PP(val);
     145                 :         }
     146                 : 
     147               0 :         return (retval);
     148                 : }
     149                 : /* }}} */
     150                 : 
     151                 : /* {{{ php_store_class_name
     152                 :  */
     153                 : PHPAPI void php_store_class_name(zval *object, const char *name, zend_uint len)
     154               0 : {
     155                 :         zval *val;
     156                 :         TSRMLS_FETCH();
     157                 : 
     158               0 :         MAKE_STD_ZVAL(val);
     159                 : 
     160               0 :         Z_TYPE_P(val)   = IS_STRING;
     161               0 :         Z_STRVAL_P(val) = estrndup(name, len);
     162               0 :         Z_STRLEN_P(val) = len;
     163                 : 
     164               0 :         zend_hash_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER), &val, sizeof(val), NULL);
     165               0 : }
     166                 : /* }}} */
     167                 : 
     168                 : /*
     169                 :  * Local variables:
     170                 :  * tab-width: 4
     171                 :  * c-basic-offset: 4
     172                 :  * End:
     173                 :  * vim600: sw=4 ts=4 fdm=marker
     174                 :  * vim<600: sw=4 ts=4
     175                 :  */

Generated by: LTP GCOV extension version 1.5