PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - standard - incomplete_class.c
Test: PHP Code Coverage
Date: 2009-11-23 Instrumented lines: 60
Code covered: 96.7 % Executed lines: 58
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 6                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2009 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                 : /* $Id: incomplete_class.c 281094 2009-05-25 14:32:15Z felipe $ */
      20                 : 
      21                 : #include "php.h"
      22                 : #include "basic_functions.h"
      23                 : #include "php_incomplete_class.h"
      24                 : 
      25                 : #define INCOMPLETE_CLASS_MSG \
      26                 :                 "The script tried to execute a method or "  \
      27                 :                 "access a property of an incomplete object. " \
      28                 :                 "Please ensure that the class definition \"%s\" of the object " \
      29                 :                 "you are trying to operate on was loaded _before_ " \
      30                 :                 "unserialize() gets called or provide a __autoload() function " \
      31                 :                 "to load the class definition "
      32                 : 
      33                 : static zend_object_handlers php_incomplete_object_handlers;
      34                 : 
      35                 : /* {{{ incomplete_class_message
      36                 :  */
      37                 : static void incomplete_class_message(zval *object, int error_type TSRMLS_DC)
      38              15 : {
      39                 :         zstr class_name;
      40              15 :         zend_bool class_name_alloced = 1;
      41                 : 
      42              15 :         class_name = php_lookup_class_name(object, NULL);
      43                 :         
      44                 :         /* FIXME: Unicode support??? */
      45              15 :         if (!class_name.s) {
      46               4 :                 class_name_alloced = 0;
      47               4 :                 class_name.s = "unknown";
      48                 :         }
      49                 :         
      50              15 :         php_error_docref(NULL TSRMLS_CC, error_type, INCOMPLETE_CLASS_MSG, class_name);
      51                 : 
      52              14 :         if (class_name_alloced) {
      53              10 :                 efree(class_name.v);
      54                 :         }
      55              14 : }
      56                 : /* }}} */
      57                 : 
      58                 : static zval *incomplete_class_get_property(zval *object, zval *member, int type TSRMLS_DC) /* {{{ */
      59               7 : {
      60               7 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      61                 :         
      62               7 :         if (type == BP_VAR_W || type == BP_VAR_RW) {
      63               0 :                 return EG(error_zval_ptr);
      64                 :         } else {
      65               7 :                 return EG(uninitialized_zval_ptr);
      66                 :         }
      67                 : }
      68                 : /* }}} */
      69                 : 
      70                 : static void incomplete_class_write_property(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */
      71               3 : {
      72               3 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      73               3 : }
      74                 : /* }}} */
      75                 :         
      76                 : static zval **incomplete_class_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC) /* {{{ */
      77               1 : {
      78               1 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      79               1 :         return &EG(error_zval_ptr);
      80                 : }
      81                 : /* }}} */
      82                 : 
      83                 : static void incomplete_class_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */
      84               1 : {
      85               1 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      86               1 : }
      87                 : /* }}} */
      88                 : 
      89                 : static int incomplete_class_has_property(zval *object, zval *member, int check_empty TSRMLS_DC) /* {{{ */
      90               2 : {
      91               2 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      92               2 :         return 0;
      93                 : }
      94                 : /* }}} */
      95                 : 
      96                 : static union _zend_function *incomplete_class_get_method(zval **object, zstr method, int method_len TSRMLS_DC) /* {{{ */
      97               1 : {
      98               1 :         incomplete_class_message(*object, E_ERROR TSRMLS_CC);
      99               0 :         return NULL;
     100                 : }
     101                 : /* }}} */
     102                 : 
     103                 : /* {{{ php_create_incomplete_class
     104                 :  */
     105                 : static zend_object_value php_create_incomplete_object(zend_class_entry *class_type TSRMLS_DC)
     106              15 : {
     107                 :         zend_object *object;
     108                 :         zend_object_value value;
     109                 :         
     110              15 :         value = zend_objects_new(&object, class_type TSRMLS_CC);
     111              15 :         value.handlers = &php_incomplete_object_handlers;
     112                 :         
     113              15 :         ALLOC_HASHTABLE(object->properties);
     114              15 :         zend_u_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0, UG(unicode));
     115              15 :         return value;
     116                 : }
     117                 : 
     118                 : PHPAPI zend_class_entry *php_create_incomplete_class(TSRMLS_D)
     119           17007 : {
     120                 :         zend_class_entry incomplete_class;
     121                 : 
     122           17007 :         INIT_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL);
     123           17007 :         incomplete_class.create_object = php_create_incomplete_object;
     124                 : 
     125           17007 :         memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
     126           17007 :         php_incomplete_object_handlers.read_property = incomplete_class_get_property;
     127           17007 :         php_incomplete_object_handlers.has_property = incomplete_class_has_property;
     128           17007 :         php_incomplete_object_handlers.unset_property = incomplete_class_unset_property;
     129           17007 :         php_incomplete_object_handlers.write_property = incomplete_class_write_property;
     130           17007 :         php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr;
     131           17007 :     php_incomplete_object_handlers.get_method = incomplete_class_get_method;
     132                 :         
     133           17007 :         return zend_register_internal_class(&incomplete_class TSRMLS_CC);
     134                 : }
     135                 : /* }}} */
     136                 : 
     137                 : /* {{{ php_lookup_class_name
     138                 :  */
     139                 : PHPAPI zstr php_lookup_class_name(zval *object, zend_uint *nlen)
     140              18 : {
     141                 :         zval **val;
     142              18 :         zstr retval = NULL_ZSTR;
     143                 :         HashTable *object_properties;
     144                 :         TSRMLS_FETCH();
     145                 : 
     146              18 :         object_properties = Z_OBJPROP_P(object);
     147                 : 
     148              18 :         if (zend_hash_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER), (void **) &val) == SUCCESS) {
     149              13 :                 retval.u = eustrndup(Z_USTRVAL_PP(val), Z_USTRLEN_PP(val));
     150                 : 
     151              13 :                 if (nlen) {
     152               2 :                         *nlen = Z_UNILEN_PP(val);
     153                 :                 }
     154                 :         }
     155                 : 
     156              18 :         return retval;
     157                 : }
     158                 : /* }}} */
     159                 : 
     160                 : /* {{{ php_store_class_name
     161                 :  */
     162                 : PHPAPI void php_store_class_name(zval *object, zstr name, zend_uint len)
     163              12 : {
     164                 :         zval *val;
     165                 :         TSRMLS_FETCH();
     166                 : 
     167              12 :         MAKE_STD_ZVAL(val);
     168              12 :         ZVAL_UNICODEL(val, name.u, len, 1);
     169                 : 
     170              12 :         zend_hash_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER), &val, sizeof(val), NULL);
     171              12 : }
     172                 : /* }}} */
     173                 : 
     174                 : /*
     175                 :  * Local variables:
     176                 :  * tab-width: 4
     177                 :  * c-basic-offset: 4
     178                 :  * End:
     179                 :  * vim600: sw=4 ts=4 fdm=marker
     180                 :  * vim<600: sw=4 ts=4
     181                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Mon, 23 Nov 2009 17:39:42 +0000 (35 hours ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.