summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2015-02-10 15:43:23 +0100
committerBob Weinand <bobwei9@hotmail.com>2015-02-10 15:47:17 +0100
commit830d3d79b3744db021f2183857c5a625e96c6315 (patch)
tree91c21b780a676263c030193003096ffd9e9bbff6 /ext
parent6c9d75b44d559f9d35fba01b1f6eb16aef4c23b1 (diff)
downloadphp-git-830d3d79b3744db021f2183857c5a625e96c6315.tar.gz
Revert "Revert "Improve and generalize class constant substitution""
This reverts commit 400e65e955f08ad6ae57c1a15be04d5852107252. Removing ReflectionParameter::getDefaultValueConstantName() and isDefaultValueConstant() They become useless with such optimizations and already anyway are (e.g. CONSTANT?:CONSTANT ... yields the constant back without telling isDefaultValueConstant() about it etc.)
Diffstat (limited to 'ext')
-rw-r--r--ext/reflection/php_reflection.c50
-rw-r--r--ext/reflection/tests/ReflectionParameter_DefaultValue.phpt46
-rw-r--r--ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt52
-rw-r--r--ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt30
-rw-r--r--ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt23
5 files changed, 46 insertions, 155 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 92b5d9da5f..51c2c15405 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -2619,54 +2619,6 @@ ZEND_METHOD(reflection_parameter, getDefaultValue)
}
/* }}} */
-/* {{{ proto public bool ReflectionParameter::isDefaultValueConstant()
- Returns whether the default value of this parameter is constant */
-ZEND_METHOD(reflection_parameter, isDefaultValueConstant)
-{
- zend_op *precv;
- parameter_reference *param;
-
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
-
- param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- if (!param) {
- RETURN_FALSE;
- }
-
- precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
- if (precv && Z_TYPE_P(RT_CONSTANT(&param->fptr->op_array, precv->op2)) == IS_CONSTANT) {
- RETURN_TRUE;
- }
-
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto public mixed ReflectionParameter::getDefaultValueConstantName()
- Returns the default value's constant name if default value is constant or null */
-ZEND_METHOD(reflection_parameter, getDefaultValueConstantName)
-{
- zend_op *precv;
- parameter_reference *param;
-
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
-
- param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- if (!param) {
- return;
- }
-
- precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param);
- if (precv && Z_TYPE_P(RT_CONSTANT(&param->fptr->op_array, precv->op2)) == IS_CONSTANT) {
- RETURN_STR(zend_string_copy(Z_STR_P(RT_CONSTANT(&param->fptr->op_array, precv->op2))));
- }
-}
-/* }}} */
-
/* {{{ proto public bool ReflectionParameter::isVariadic()
Returns whether this parameter is a variadic parameter */
ZEND_METHOD(reflection_parameter, isVariadic)
@@ -6038,8 +5990,6 @@ static const zend_function_entry reflection_parameter_functions[] = {
ZEND_ME(reflection_parameter, isOptional, arginfo_reflection__void, 0)
ZEND_ME(reflection_parameter, isDefaultValueAvailable, arginfo_reflection__void, 0)
ZEND_ME(reflection_parameter, getDefaultValue, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, isDefaultValueConstant, arginfo_reflection__void, 0)
- ZEND_ME(reflection_parameter, getDefaultValueConstantName, arginfo_reflection__void, 0)
ZEND_ME(reflection_parameter, isVariadic, arginfo_reflection__void, 0)
PHP_FE_END
};
diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValue.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValue.phpt
new file mode 100644
index 0000000000..b3f77ca2b5
--- /dev/null
+++ b/ext/reflection/tests/ReflectionParameter_DefaultValue.phpt
@@ -0,0 +1,46 @@
+--TEST--
+ReflectionParameter::getDefaultValue() with constants and non-compile-time ASTs
+--FILE--
+<?php
+
+define("CONST_TEST_1", "const1");
+
+function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1) {
+ echo $test;
+}
+$reflect = new ReflectionFunction('ReflectionParameterTest');
+foreach($reflect->getParameters() as $param) {
+ if($param->isDefaultValueAvailable()) {
+ var_dump($param->getDefaultValue());
+ }
+}
+
+class Foo2 {
+ const bar = 'Foo2::bar';
+}
+
+class Foo {
+ const bar = 'Foo::bar';
+
+ public function baz($param1 = self::bar, $param2 = Foo2::bar, $param3 = CONST_TEST_1 . "+string") {
+ }
+}
+
+$method = new ReflectionMethod('Foo', 'baz');
+$params = $method->getParameters();
+
+foreach ($params as $param) {
+ if ($param->isDefaultValueAvailable()) {
+ var_dump($param->getDefaultValue());
+ }
+}
+?>
+==DONE==
+--EXPECT--
+array(0) {
+}
+string(6) "const1"
+string(8) "Foo::bar"
+string(9) "Foo2::bar"
+string(13) "const1+string"
+==DONE==
diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt
deleted file mode 100644
index cdd00d2624..0000000000
--- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt
+++ /dev/null
@@ -1,52 +0,0 @@
---TEST--
-ReflectionParameter::isDefaultValueConstant() && getDefaultValueConstantName()
---FILE--
-<?php
-
-define("CONST_TEST_1", "const1");
-
-function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1) {
- echo $test;
-}
-$reflect = new ReflectionFunction('ReflectionParameterTest');
-foreach($reflect->getParameters() as $param) {
- if($param->getName() == 'test1') {
- var_dump($param->isDefaultValueConstant());
- }
- if($param->getName() == 'test2') {
- var_dump($param->isDefaultValueConstant());
- }
- if($param->isDefaultValueAvailable() && $param->isDefaultValueConstant()) {
- var_dump($param->getDefaultValueConstantName());
- }
-}
-
-class Foo2 {
- const bar = 'Foo2::bar';
-}
-
-class Foo {
- const bar = 'Foo::bar';
-
- public function baz($param1 = self::bar, $param2=Foo2::bar, $param3=CONST_TEST_1) {
- }
-}
-
-$method = new ReflectionMethod('Foo', 'baz');
-$params = $method->getParameters();
-
-foreach ($params as $param) {
- if ($param->isDefaultValueConstant()) {
- var_dump($param->getDefaultValueConstantName());
- }
-}
-?>
-==DONE==
---EXPECT--
-bool(false)
-bool(true)
-string(12) "CONST_TEST_1"
-string(9) "self::bar"
-string(9) "Foo2::bar"
-string(12) "CONST_TEST_1"
-==DONE==
diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt
deleted file mode 100644
index 1ee9e93735..0000000000
--- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt
+++ /dev/null
@@ -1,30 +0,0 @@
---TEST--
-ReflectionParameter::isDefaultValueConstant() && getDefaultValueConstantName() for namespace
---FILE--
-<?php
-
-namespace ReflectionTestNamespace {
- CONST TEST_CONST_1 = "Test Const 1";
-
- class TestClass {
- const TEST_CONST_2 = "Test Const 2 in class";
- }
-}
-
-namespace {
- function ReflectionParameterTest($test=ReflectionTestNamespace\TestClass::TEST_CONST_2, $test2 = ReflectionTestNamespace\CONST_TEST_1) {
- echo $test;
- }
- $reflect = new ReflectionFunction('ReflectionParameterTest');
- foreach($reflect->getParameters() as $param) {
- if($param->isDefaultValueAvailable() && $param->isDefaultValueConstant()) {
- echo $param->getDefaultValueConstantName() . "\n";
- }
- }
- echo "==DONE==";
-}
-?>
---EXPECT--
-ReflectionTestNamespace\TestClass::TEST_CONST_2
-ReflectionTestNamespace\CONST_TEST_1
-==DONE==
diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt
deleted file mode 100644
index a2c2d24582..0000000000
--- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt
+++ /dev/null
@@ -1,23 +0,0 @@
---TEST--
-ReflectionParameter::getDefaultValueConstant() should raise exception on non optional parameter
---FILE--
-<?php
-
-define("CONST_TEST_1", "const1");
-
-function ReflectionParameterTest($test, $test2 = CONST_TEST_1) {
- echo $test;
-}
-$reflect = new ReflectionFunction('ReflectionParameterTest');
-foreach($reflect->getParameters() as $param) {
- try {
- echo $param->getDefaultValueConstantName() . "\n";
- }
- catch(ReflectionException $e) {
- echo $e->getMessage() . "\n";
- }
-}
-?>
---EXPECT--
-Internal error: Failed to retrieve the default value
-CONST_TEST_1