Skip to content

Commit 461e140

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents 4ac954a + af37d58 commit 461e140

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Calling exception getters when properties hold references
3+
--FILE--
4+
<?php
5+
6+
class MyException extends Exception {
7+
public function __construct(&$refMsg, &$refCode, &$refFile, &$refLine) {
8+
$this->message =& $refMsg;
9+
$this->code =& $refCode;
10+
$this->file =& $refFile;
11+
$this->line =& $refLine;
12+
}
13+
}
14+
15+
$refMsg = "foo";
16+
$refCode = 0;
17+
$refFile = "foobar";
18+
$refLine = 42;
19+
$ex = new MyException($refMsg, $refCode, $refFile, $refLine);
20+
var_dump($ex->getMessage());
21+
var_dump($ex->getCode());
22+
var_dump($ex->getFile());
23+
var_dump($ex->getLine());
24+
25+
?>
26+
--EXPECT--
27+
string(3) "foo"
28+
int(0)
29+
string(6) "foobar"
30+
int(42)

Zend/zend_exceptions.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,71 +400,83 @@ ZEND_METHOD(error_exception, __construct)
400400
Get the file in which the exception occurred */
401401
ZEND_METHOD(exception, getFile)
402402
{
403-
zval rv;
403+
zval *prop, rv;
404404

405405
DEFAULT_0_PARAMS;
406406

407-
ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_FILE));
407+
prop = GET_PROPERTY(getThis(), ZEND_STR_FILE);
408+
ZVAL_DEREF(prop);
409+
ZVAL_COPY(return_value, prop);
408410
}
409411
/* }}} */
410412

411413
/* {{{ proto int Exception|Error::getLine()
412414
Get the line in which the exception occurred */
413415
ZEND_METHOD(exception, getLine)
414416
{
415-
zval rv;
417+
zval *prop, rv;
416418

417419
DEFAULT_0_PARAMS;
418420

419-
ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_LINE));
421+
prop = GET_PROPERTY(getThis(), ZEND_STR_LINE);
422+
ZVAL_DEREF(prop);
423+
ZVAL_COPY(return_value, prop);
420424
}
421425
/* }}} */
422426

423427
/* {{{ proto string Exception|Error::getMessage()
424428
Get the exception message */
425429
ZEND_METHOD(exception, getMessage)
426430
{
427-
zval rv;
431+
zval *prop, rv;
428432

429433
DEFAULT_0_PARAMS;
430434

431-
ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_MESSAGE));
435+
prop = GET_PROPERTY(getThis(), ZEND_STR_MESSAGE);
436+
ZVAL_DEREF(prop);
437+
ZVAL_COPY(return_value, prop);
432438
}
433439
/* }}} */
434440

435441
/* {{{ proto int Exception|Error::getCode()
436442
Get the exception code */
437443
ZEND_METHOD(exception, getCode)
438444
{
439-
zval rv;
445+
zval *prop, rv;
440446

441447
DEFAULT_0_PARAMS;
442448

443-
ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_CODE));
449+
prop = GET_PROPERTY(getThis(), ZEND_STR_CODE);
450+
ZVAL_DEREF(prop);
451+
ZVAL_COPY(return_value, prop);
444452
}
445453
/* }}} */
446454

447455
/* {{{ proto array Exception|Error::getTrace()
448456
Get the stack trace for the location in which the exception occurred */
449457
ZEND_METHOD(exception, getTrace)
450458
{
451-
zval rv;
459+
zval *prop, rv;
452460

453461
DEFAULT_0_PARAMS;
454462

455-
ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_TRACE));
463+
prop = GET_PROPERTY(getThis(), ZEND_STR_TRACE);
464+
ZVAL_DEREF(prop);
465+
ZVAL_COPY(return_value, prop);
456466
}
457467
/* }}} */
458468

459469
/* {{{ proto int ErrorException::getSeverity()
460470
Get the exception severity */
461471
ZEND_METHOD(error_exception, getSeverity)
462472
{
463-
zval rv;
473+
zval *prop, rv;
464474

465475
DEFAULT_0_PARAMS;
466476

467-
ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_SEVERITY));
477+
prop = GET_PROPERTY(getThis(), ZEND_STR_SEVERITY);
478+
ZVAL_DEREF(prop);
479+
ZVAL_COPY(return_value, prop);
468480
}
469481
/* }}} */
470482

0 commit comments

Comments
 (0)