1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Files
archived-php-src/tests/classes/constants_basic_001.phpt
Peter Kokot b746e69887 Sync leading and final newlines in *.phpt sections
This patch adds missing newlines, trims multiple redundant final
newlines into a single one, and trims redundant leading newlines in all
*.phpt sections.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-15 04:32:30 +02:00

92 lines
1.8 KiB
PHP

--TEST--
Class constant declarations
--FILE--
<?php
define('DEFINED', 1234);
$def = 456;
define('DEFINED_TO_VAR', $def);
define('DEFINED_TO_UNDEF_VAR', $undef);
class C
{
const c0 = UNDEFINED;
const c1 = 1, c2 = 1.5;
const c3 = + 1, c4 = + 1.5;
const c5 = -1, c6 = -1.5;
const c7 = __LINE__;
const c8 = __FILE__;
const c9 = __CLASS__;
const c10 = __METHOD__;
const c11 = __FUNCTION__;
const c12 = DEFINED;
const c13 = DEFINED_TO_VAR;
const c14 = DEFINED_TO_UNDEF_VAR;
const c15 = "hello1";
const c16 = 'hello2';
const c17 = C::c16;
const c18 = self::c17;
}
echo "\nAttempt to access various kinds of class constants:\n";
var_dump(C::c0);
var_dump(C::c1);
var_dump(C::c2);
var_dump(C::c3);
var_dump(C::c4);
var_dump(C::c5);
var_dump(C::c6);
var_dump(C::c7);
var_dump(C::c8);
var_dump(C::c9);
var_dump(C::c10);
var_dump(C::c11);
var_dump(C::c12);
var_dump(C::c13);
var_dump(C::c14);
var_dump(C::c15);
var_dump(C::c16);
var_dump(C::c17);
var_dump(C::c18);
echo "\nExpecting fatal error:\n";
var_dump(C::c19);
echo "\nYou should not see this.";
?>
--EXPECTF--
Notice: Undefined variable: undef in %s on line 5
Attempt to access various kinds of class constants:
Warning: Use of undefined constant UNDEFINED - assumed 'UNDEFINED' (this will throw an Error in a future version of PHP) in %s on line %d
string(9) "UNDEFINED"
int(1)
float(1.5)
int(1)
float(1.5)
int(-1)
float(-1.5)
int(15)
string(%d) "%s"
string(1) "C"
string(1) "C"
string(0) ""
int(1234)
int(456)
NULL
string(6) "hello1"
string(6) "hello2"
string(6) "hello2"
string(6) "hello2"
Expecting fatal error:
Fatal error: Uncaught Error: Undefined class constant 'c19' in %s:53
Stack trace:
#0 {main}
thrown in %s on line 53