Opened 13 months ago

Closed 13 months ago

Last modified 12 months ago

#318 closed defect (fixed)

Problem with constants in class

Reported by: drakmor Owned by: moo
Priority: major Milestone: 3.1.0
Component: disassembler Version: 3.0.3
Keywords: Cc:
Application: PHP Version: 5.3.26
Other Exts: SAPI: Irrelevant
Probability: Always Blocked By:
Blocking:

Description

No decode constants when it's used as keys in array.

Test code:

class Cl
{
  const C = "123";
  public $v3  = Cl::C;
  private $v4  = self::C;
  private $v5 = array(self::C);
  static $v = array(Cl::C=>"aaa");
  static $v6 = array("aaa"=>Cl::C);
  static $v2 = array(self::C=>"aaa");
  private $v7 = array(self::C=>"aaa");
  private $v8 = array("aaa"=>self::C);
}

Result:

<?php

class Cl
{
        const C = '123';

        public $v3 = Cl::C;
        private $v4 = self::C;
        private $v5 = array(self::C);
        static public $v = array('Cl::C' . "\0" . ' => NULL);
        static public $v6 = array('aaa' => Cl::C);
        static public $v2 = array('self::C' . "\0" . ' => NULL);
        private $v7 = array('self::C' . "\0" . ' => NULL);
        private $v8 = array('aaa' => self::C);
}
?>

Result of xcache_get_special_value():

array (
  'Cl::C' . "\0" . ' => NULL,
)

Change History (9)

comment:1 Changed 13 months ago by moo

fixed in [1343]. local static still need fix for older PHP version

comment:2 Changed 13 months ago by moo

  • Milestone changed from undecided to 3.1.0
  • Resolution set to fixed
  • Status changed from new to closed

comment:3 Changed 12 months ago by drakmor

Fix for IS_CONSTANT_INDEX like this

  PHP_FUNCTION(xcache_get_special_value)
  {
 
  	zval *value;
  
  	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) {
  		return;
  	}
  	switch ((Z_TYPE_P(value) & IS_CONSTANT_TYPE_MASK)) {
  	case IS_CONSTANT:
  		*return_value = *value;
  		zval_copy_ctor(return_value);
 		Z_TYPE_P(return_value) = UNISW(IS_STRING, UG(unicode) ? IS_UNICODE : IS_STRING);
  		break;
  
  	case IS_CONSTANT_ARRAY:
  		*return_value = *value;
  		zval_copy_ctor(return_value);
 		Z_TYPE_P(return_value)= IS_ARRAY;
  		break;
  
  	default:
 		if (Z_TYPE_P(value) & IS_CONSTANT_INDEX) {
 			*return_value = *value;
 			zval_copy_ctor(return_value);
 		} else RETURN_NULL();
  	}
 	
 	Z_TYPE_P(return_value) &= ~IS_CONSTANT_INDEX; 
  }
Last edited 12 months ago by drakmor (previous) (diff)

comment:4 Changed 12 months ago by moo

what version of PHP does this new patch is for?

comment:5 Changed 12 months ago by drakmor

Tested on 5.3/5.4 with uncommented

 	Z_TYPE_P(return_value) &= ~IS_CONSTANT_INDEX; 

But it is clean flag and need analyse type before get_special_value().

If comment cleaning flag - segfault

Last edited 12 months ago by drakmor (previous) (diff)

comment:6 Changed 12 months ago by moo

for 5.3/5.4, it's already fixed in trunk, and it works for your test input without your patch. I don't see a necessary

comment:7 Changed 12 months ago by drakmor

test: private $v7 = array(self::C=>"aaa");
trunk: private $v7 = array(self::C=>NULL);
my patch: private $v7 = array(self::C=>"aaa");

comment:8 Changed 12 months ago by moo

In 1374:

Decompiler: fixes #318 (support for const in static array index/value)

comment:9 Changed 12 months ago by moo

Thanks drakmor for pointing out a missing case in sample php

Note: See TracTickets for help on using tickets.