Skip to content

Commit 1278c20

Browse files
committed
add more tests and fix a memory error
1 parent 24cd8c2 commit 1278c20

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

Zend/zend_namespaces.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "zend_hash.h"
2323

2424
zend_class_entry *create_namespace(zend_string *name) {
25-
zend_class_entry *ns = pemalloc(sizeof(zend_class_entry), 0);
25+
zend_class_entry *ns = malloc(sizeof(zend_class_entry));
2626
zend_initialize_class_data(ns, 1);
2727
ns->type = ZEND_NAMESPACE_CLASS;
2828
ns->ce_flags |= ZEND_ACC_UNINSTANTIABLE;
@@ -39,8 +39,8 @@ static zend_class_entry *insert_namespace(const zend_string *name) {
3939
const char *pos = start;
4040
size_t len = 0;
4141

42-
while (pos < end) {
43-
if (*pos == '\\') {
42+
while (pos <= end) {
43+
if (pos == end || *pos == '\\') {
4444
len = pos - start;
4545
zend_string *needle = zend_string_init(ZSTR_VAL(name), len, 0);
4646

@@ -100,10 +100,6 @@ void zend_destroy_namespaces(void) {
100100
zend_hash_destroy(EG(namespaces));
101101
FREE_HASHTABLE(EG(namespaces));
102102
EG(namespaces) = NULL;
103-
}
104-
105-
if (EG(global_namespace) != NULL) {
106-
pefree(EG(global_namespace), 0);
107103
EG(global_namespace) = NULL;
108104
}
109105
}

Zend/zend_opcode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ ZEND_API void destroy_zend_class(zval *zv)
432432
}
433433
break;
434434
case ZEND_INTERNAL_CLASS:
435+
case ZEND_NAMESPACE_CLASS:
435436
if (ce->doc_comment) {
436437
zend_string_release_ex(ce->doc_comment, 1);
437438
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
failed inheritance
3+
--FILE--
4+
<?php
5+
6+
class Outer {
7+
public class Middle {
8+
}
9+
public static function testSelf(): Middle {
10+
return new Middle();
11+
}
12+
}
13+
14+
class Outer2 extends Outer {
15+
public class Middle {
16+
}
17+
18+
public static function testParent(): Outer\Middle {
19+
return new Outer\Middle();
20+
}
21+
22+
public static function testSelf(): Middle {
23+
return new Middle();
24+
}
25+
}
26+
27+
var_dump(Outer::testSelf());
28+
var_dump(Outer2::testParent());
29+
var_dump(Outer2::testSelf());
30+
var_dump(Outer2::testSelf());
31+
32+
?>
33+
--EXPECTF--
34+
Fatal error: Declaration of Outer2::testSelf(): Outer2\middle must be compatible with Outer::testSelf(): Outer\middle in %s on line %d

0 commit comments

Comments
 (0)