Browse Source
Revert removal of two ReflectionParameter functions
Revert removal of two ReflectionParameter functions
Rather fix them for now by exempting function parameter defaults from *any* (non-ct) constant substitution (also from persistent constant substitution, which was already broken before)pull/1075/head
7 changed files with 169 additions and 49 deletions
-
14Zend/zend_compile.c
-
3Zend/zend_compile.h
-
50ext/reflection/php_reflection.c
-
46ext/reflection/tests/ReflectionParameter_DefaultValue.phpt
-
52ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt
-
30ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic2.phpt
-
23ext/reflection/tests/ReflectionParameter_DefaultValueConstant_error.phpt
@ -1,46 +0,0 @@ |
|||
--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== |
|||
@ -0,0 +1,52 @@ |
|||
--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== |
|||
@ -0,0 +1,30 @@ |
|||
--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== |
|||
@ -0,0 +1,23 @@ |
|||
--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 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue