Skip to content

Commit 3db6aad

Browse files
committed
Promote warning to exception in constant() function
1 parent bbd1617 commit 3db6aad

File tree

7 files changed

+48
-27
lines changed

7 files changed

+48
-27
lines changed

Zend/tests/018.phpt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ constant() tests
33
--FILE--
44
<?php
55

6-
var_dump(constant(""));
76

87
define("TEST_CONST", 1);
9-
var_dump(constant("TEST_CONST"));
8+
try {
9+
var_dump(constant(""));
10+
} catch (ValueError $exception) {
11+
echo $exception->getMessage() . "\n";
12+
}
13+
14+
try {
15+
constant('::');
16+
} catch (ValueError $exception) {
17+
echo $exception->getMessage() . "\n";
18+
}
1019

1120
define("TEST_CONST2", "test");
1221
var_dump(constant("TEST_CONST2"));
1322

1423
echo "Done\n";
1524
?>
1625
--EXPECTF--
17-
Warning: constant(): Couldn't find constant in %s on line %d
18-
NULL
19-
int(1)
26+
Couldn't find constant
27+
Couldn't find constant ::
2028
string(4) "test"
2129
Done

Zend/tests/bug51791.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ Bug #51791 (constant() failed to check undefined constant and php interpreter st
66
class A {
77
const B = 1;
88
}
9-
var_dump(constant('A::B1'));
109

10+
try {
11+
constant('A::B1');
12+
} catch (ValueError $exception) {
13+
echo $exception->getMessage() . "\n";
14+
}
1115
?>
12-
--EXPECTF--
13-
Warning: constant(): Couldn't find constant A::B1 in %s on line %d
14-
NULL
16+
--EXPECT--
17+
Couldn't find constant A::B1

ext/standard/basic_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ PHP_FUNCTION(constant)
20402040
}
20412041
} else {
20422042
if (!EG(exception)) {
2043-
php_error_docref(NULL, E_WARNING, "Couldn't find constant %s", ZSTR_VAL(const_name));
2043+
zend_value_error("Couldn't find constant %s", ZSTR_VAL(const_name));
20442044
}
20452045
RETURN_NULL();
20462046
}

ext/standard/tests/general_functions/bug72920.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ class Foo {
66
private const C1 = "a";
77
}
88

9-
var_dump(constant('Foo::C1'));
10-
--EXPECTF--
11-
Warning: constant(): Couldn't find constant Foo::C1 in %s on line %d
12-
NULL
9+
try {
10+
constant('Foo::C1');
11+
} catch (ValueError $exception) {
12+
echo $exception->getMessage() . "\n";
13+
}
14+
--EXPECT--
15+
Couldn't find constant Foo::C1

tests/classes/constants_visibility_002.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ class A {
1414

1515
A::staticConstDump();
1616
(new A())->constDump();
17-
constant('A::protectedConst');
17+
try {
18+
constant('A::protectedConst');
19+
} catch (ValueError $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
1822

1923
?>
20-
--EXPECTF--
24+
--EXPECT--
2125
string(14) "protectedConst"
2226
string(14) "protectedConst"
23-
24-
Warning: constant(): Couldn't find constant A::protectedConst in %s on line %d
27+
Couldn't find constant A::protectedConst

tests/classes/constants_visibility_003.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ class A {
1414

1515
A::staticConstDump();
1616
(new A())->constDump();
17-
constant('A::privateConst');
18-
17+
try {
18+
constant('A::privateConst');
19+
} catch (ValueError $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
1922
?>
20-
--EXPECTF--
23+
--EXPECT--
2124
string(12) "privateConst"
2225
string(12) "privateConst"
23-
24-
Warning: constant(): Couldn't find constant A::privateConst in %s on line %d
26+
Couldn't find constant A::privateConst

tests/lang/bug44827.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ Testfest Munich 2009
77
--FILE--
88
<?php
99
define('::', true);
10-
var_dump(constant('::'));
10+
try {
11+
constant('::');
12+
} catch (ValueError $exception) {
13+
echo $exception->getMessage() . "\n";
14+
}
1115
?>
1216
--EXPECTF--
1317
Warning: Class constants cannot be defined or redefined in %s on line %d
14-
15-
Warning: constant(): Couldn't find constant :: in %s on line %d
16-
NULL
18+
Couldn't find constant ::

0 commit comments

Comments
 (0)