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

LCOV - code coverage report
Current view: top level - ext/standard - incomplete_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 50 52 96.2 %
Date: 2014-10-22 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 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$ */
      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          15 : static void incomplete_class_message(zval *object, int error_type TSRMLS_DC)
      38             : {
      39             :         zend_string *class_name;
      40             : 
      41          15 :         class_name = php_lookup_class_name(object);
      42             : 
      43          15 :         if (class_name) {
      44          11 :                 php_error_docref(NULL TSRMLS_CC, error_type, INCOMPLETE_CLASS_MSG, class_name->val);
      45             :                 zend_string_release(class_name);
      46             :         } else {
      47           4 :                 php_error_docref(NULL TSRMLS_CC, error_type, INCOMPLETE_CLASS_MSG, "unknown");
      48             :         }
      49          14 : }
      50             : /* }}} */
      51             : 
      52           7 : static zval *incomplete_class_get_property(zval *object, zval *member, int type, void **cache_slot, zval *rv TSRMLS_DC) /* {{{ */
      53             : {
      54           7 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      55             : 
      56           7 :         if (type == BP_VAR_W || type == BP_VAR_RW) {
      57           0 :                 return &EG(error_zval);
      58             :         } else {
      59           7 :                 return &EG(uninitialized_zval);
      60             :         }
      61             : }
      62             : /* }}} */
      63             : 
      64           3 : static void incomplete_class_write_property(zval *object, zval *member, zval *value, void **cache_slot TSRMLS_DC) /* {{{ */
      65             : {
      66           3 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      67           3 : }
      68             : /* }}} */
      69             : 
      70           1 : static zval *incomplete_class_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot TSRMLS_DC) /* {{{ */
      71             : {
      72           1 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      73           1 :         return &EG(error_zval);
      74             : }
      75             : /* }}} */
      76             : 
      77           1 : static void incomplete_class_unset_property(zval *object, zval *member, void **cache_slot TSRMLS_DC) /* {{{ */
      78             : {
      79           1 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      80           1 : }
      81             : /* }}} */
      82             : 
      83           2 : static int incomplete_class_has_property(zval *object, zval *member, int check_empty, void **cache_slot TSRMLS_DC) /* {{{ */
      84             : {
      85           2 :         incomplete_class_message(object, E_NOTICE TSRMLS_CC);
      86           2 :         return 0;
      87             : }
      88             : /* }}} */
      89             : 
      90           1 : static union _zend_function *incomplete_class_get_method(zend_object **object, zend_string *method, const zval *key TSRMLS_DC) /* {{{ */
      91             : {
      92             :         zval zobject;
      93             : 
      94           1 :         ZVAL_OBJ(&zobject, *object);
      95           1 :         incomplete_class_message(&zobject, E_ERROR TSRMLS_CC);
      96           0 :         return NULL;
      97             : }
      98             : /* }}} */
      99             : 
     100             : /* {{{ php_create_incomplete_class
     101             :  */
     102          12 : static zend_object *php_create_incomplete_object(zend_class_entry *class_type TSRMLS_DC)
     103             : {
     104             :         zend_object *object;
     105             : 
     106          12 :         object = zend_objects_new( class_type TSRMLS_CC);
     107          12 :         object->handlers = &php_incomplete_object_handlers;
     108             : 
     109          12 :         object_properties_init(object, class_type);
     110             : 
     111          12 :         return object;
     112             : }
     113             : 
     114       20423 : PHPAPI zend_class_entry *php_create_incomplete_class(TSRMLS_D)
     115             : {
     116             :         zend_class_entry incomplete_class;
     117             : 
     118       20423 :         INIT_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL);
     119       20423 :         incomplete_class.create_object = php_create_incomplete_object;
     120             : 
     121       20423 :         memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
     122       20423 :         php_incomplete_object_handlers.read_property = incomplete_class_get_property;
     123       20423 :         php_incomplete_object_handlers.has_property = incomplete_class_has_property;
     124       20423 :         php_incomplete_object_handlers.unset_property = incomplete_class_unset_property;
     125       20423 :         php_incomplete_object_handlers.write_property = incomplete_class_write_property;
     126       20423 :         php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr;
     127       20423 :     php_incomplete_object_handlers.get_method = incomplete_class_get_method;
     128             : 
     129       20423 :         return zend_register_internal_class(&incomplete_class TSRMLS_CC);
     130             : }
     131             : /* }}} */
     132             : 
     133             : /* {{{ php_lookup_class_name
     134             :  */
     135          18 : PHPAPI zend_string *php_lookup_class_name(zval *object)
     136             : {
     137             :         zval *val;
     138             :         HashTable *object_properties;
     139             :         TSRMLS_FETCH();
     140             : 
     141          18 :         object_properties = Z_OBJPROP_P(object);
     142             : 
     143          18 :         if ((val = zend_hash_str_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1)) != NULL) {
     144          26 :                 return zend_string_copy(Z_STR_P(val));
     145             :         }
     146             : 
     147           5 :         return NULL;
     148             : }
     149             : /* }}} */
     150             : 
     151             : /* {{{ php_store_class_name
     152             :  */
     153           9 : PHPAPI void php_store_class_name(zval *object, const char *name, uint32_t len)
     154             : {
     155             :         zval val;
     156             :         TSRMLS_FETCH();
     157             : 
     158             : 
     159          18 :         ZVAL_STRINGL(&val, name, len);
     160           9 :         zend_hash_str_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1, &val);
     161           9 : }
     162             : /* }}} */
     163             : 
     164             : /*
     165             :  * Local variables:
     166             :  * tab-width: 4
     167             :  * c-basic-offset: 4
     168             :  * End:
     169             :  * vim600: sw=4 ts=4 fdm=marker
     170             :  * vim<600: sw=4 ts=4
     171             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:58 +0000 (21 hours ago)

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