Skip to content

Commit b626540

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b527eca + 4a619aa commit b626540

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

src/main/php/lang/reflect/ClassParser.class.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,13 @@ protected function valueOf($tokens, &$i, $context, $imports) {
175175
$code.= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
176176
}
177177
}
178-
ob_start();
179178
$func= eval('return '.$code.';');
180-
$error= ob_get_clean();
181179
if (!($func instanceof \Closure)) {
182-
preg_match("/(Parse.+) in .+.php/", $error, $m);
183-
throw new IllegalStateException('In `'.$code.'`: '.$m[1]);
180+
$error= error_get_last();
181+
set_error_handler('__error', 0);
182+
trigger_error('clear_last_error');
183+
restore_error_handler();
184+
throw new IllegalStateException('In `'.$code.'`: '.ucfirst($error['message']));
184185
}
185186
return $func;
186187
} else {

src/test/php/net/xp_framework/unittest/annotations/BrokenAnnotationTest.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,17 @@ public function class_private_static_member() {
137137
$this->parse('#[@value(AnnotationParsingTest::$internal)]');
138138
}
139139

140-
#[@test, @expect(class= 'lang.ClassFormatException', withMessage= '/In `.+`: Parse error/')]
140+
#[@test, @expect(class= 'lang.ClassFormatException', withMessage= '/In `.+`: Syntax error/')]
141141
public function function_without_braces() {
142142
$this->parse('#[@value(function)]');
143143
}
144144

145-
#[@test, @expect(class= 'lang.ClassFormatException', withMessage= '/In `.+`: Parse error/')]
145+
#[@test, @expect(class= 'lang.ClassFormatException', withMessage= '/In `.+`: Syntax error/')]
146146
public function function_without_body() {
147147
$this->parse('#[@value(function())]');
148148
}
149149

150-
#[@test, @expect(class= 'lang.ClassFormatException', withMessage= '/In `.+`: Parse error/')]
150+
#[@test, @expect(class= 'lang.ClassFormatException', withMessage= '/In `.+`: Syntax error/')]
151151
public function function_without_closing_curly() {
152152
$this->parse('#[@value(function() {)]');
153153
}

src/test/php/net/xp_framework/unittest/core/NewInstanceTest.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function missingMethodImplementationFatals() {
147147
');
148148
$this->assertEquals(255, $r[0], 'exitcode');
149149
$this->assertTrue(
150-
(bool)strstr($r[1].$r[2], 'Fatal error:'),
150+
(bool)strstr($r[1].$r[2], 'Fatal error'),
151151
\xp::stringOf(['out' => $r[1], 'err' => $r[2]])
152152
);
153153
}
@@ -159,7 +159,7 @@ public function syntaxErrorFatals() {
159159
');
160160
$this->assertEquals(255, $r[0], 'exitcode');
161161
$this->assertTrue(
162-
(bool)strstr($r[1].$r[2], 'Parse error:'),
162+
(bool)strstr($r[1].$r[2], 'Parse error'),
163163
\xp::stringOf(['out' => $r[1], 'err' => $r[2]])
164164
);
165165
}

tools/class-main.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?php
22

3-
define('EPREPEND_IDENTIFIER', "\356\277\277");
43
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
54
trigger_error('This version of the XP Framework requires PHP 5.4.0+, have PHP '.PHP_VERSION.PHP_EOL, E_USER_ERROR);
65
exit(0x3d);
76
}
87

9-
// {{{ internal string __output(string buf)
10-
// Output handler. Checks for fatal errors
11-
function __output($buf) {
12-
if (false === ($s= strpos($buf, EPREPEND_IDENTIFIER))) return $buf;
13-
$l= strlen(EPREPEND_IDENTIFIER);
14-
$e= strpos($buf, EPREPEND_IDENTIFIER, $s + $l);
15-
$message= trim(substr($buf, $s + $l, $e - $l));
16-
fputs(STDOUT, substr($buf, 0, $s));
17-
fputs(STDERR, create(new Error($message))->toString());
18-
fputs(STDOUT, substr($buf, $e + $l));
19-
return '';
8+
// {{{ internal void __fatal
9+
function __fatal() {
10+
static $types= array(
11+
E_ERROR => 'Fatal error',
12+
E_USER_ERROR => 'Fatal error',
13+
E_PARSE => 'Parse error',
14+
E_COMPILE_ERROR => 'Compile error'
15+
);
16+
17+
$e= error_get_last();
18+
if (null !== $e && isset($types[$e['type']])) {
19+
__error($e['type'], $e['message'], $e['file'], $e['line']);
20+
create(new Error($types[$e['type']]))->printStackTrace();
21+
}
2022
}
2123
// }}}
2224

@@ -62,10 +64,9 @@ function __except($e) {
6264
}
6365
}
6466

65-
ini_set('error_prepend_string', EPREPEND_IDENTIFIER);
66-
ini_set('error_append_string', EPREPEND_IDENTIFIER);
67+
ini_set('display_errors', 'false');
6768
set_exception_handler('__except');
68-
ob_start('__output');
69+
register_shutdown_function('__fatal');
6970

7071
try {
7172
exit(\lang\XPClass::forName($argv[0])->getMethod('main')->invoke(null, array(array_slice($argv, 1))));

0 commit comments

Comments
 (0)