cvs: ZendEngine2 / zend_API.c zend_compile.c zend_compile.h zend_opcode.c
| From: | Zeev Suraski | Date: | Wed, 25 Feb 2004 09:25:40 +0000 |
| Subject: | cvs: ZendEngine2 / zend_API.c zend_compile.c zend_compile.h zend_opcode.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-2402@lists.php.net to get a copy of this message | ||
zeev Wed Feb 25 04:25:40 2004 EDT
Modified files:
/ZendEngine2 zend_API.c zend_compile.c zend_compile.h zend_opcode.c
Log:
- Abstract methods cannot have defaults for arguments
- Make function foo($a, $b=null) satisfy both foo($a) and foo($a, $b)
prototypes
http://cvs.php.net/diff.php/ZendEngine2/zend_API.c?r1=1.240&r2=1.241&ty=u
Index: ZendEngine2/zend_API.c
diff -u ZendEngine2/zend_API.c:1.240 ZendEngine2/zend_API.c:1.241
--- ZendEngine2/zend_API.c:1.240 Tue Feb 24 18:39:12 2004
+++ ZendEngine2/zend_API.c Wed Feb 25 04:25:36 2004
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_API.c,v 1.240 2004/02/24 23:39:12 helly Exp $ */
+/* $Id: zend_API.c,v 1.241 2004/02/25 09:25:36 zeev Exp $ */
#include "zend.h"
#include "zend_execute.h"
@@ -1220,11 +1220,14 @@
if (ptr->arg_info) {
internal_function->arg_info = ptr->arg_info+1;
internal_function->num_args = ptr->num_args;
+ /* Currently you cannot denote that the function can accept less arguments than num_args */
+ internal_function->required_num_args = ptr->num_args;
internal_function->pass_rest_by_reference = ptr->arg_info[0].pass_by_reference;
internal_function->return_reference = ptr->arg_info[0].return_reference;
} else {
internal_function->arg_info = NULL;
internal_function->num_args = 0;
+ internal_function->required_num_args = 0;
internal_function->pass_rest_by_reference = 0;
internal_function->return_reference = 0;
}
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.543&r2=1.544&ty=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.543 ZendEngine2/zend_compile.c:1.544
--- ZendEngine2/zend_compile.c:1.543 Sun Feb 15 19:34:23 2004
+++ ZendEngine2/zend_compile.c Wed Feb 25 04:25:36 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.543 2004/02/16 00:34:23 helly Exp $ */
+/* $Id: zend_compile.c,v 1.544 2004/02/25 09:25:36 zeev Exp $ */
#include "zend_language_parser.h"
#include "zend.h"
@@ -1135,9 +1135,15 @@
opline->opcode = op;
opline->result = *var;
opline->op1 = *offset;
- if ((op == ZEND_RECV_INIT)) {
+ if (op == ZEND_RECV_INIT) {
+ if ((CG(active_class_entry) && CG(active_class_entry)->ce_flags &
ZEND_ACC_INTERFACE)
+ || CG(active_op_array)->fn_flags & ZEND_ACC_ABSTRACT) {
+ CG(active_op_array)->num_args--; /* invalidate the current arg_info entry */
+ zend_error(E_COMPILE_ERROR, "Abstract methods cannot have default values for
arguments");
+ }
opline->op2 = *initialization;
} else {
+ CG(active_op_array)->required_num_args = CG(active_op_array)->num_args;
SET_UNUSED(opline->op2);
}
CG(active_op_array)->arg_info = erealloc(CG(active_op_array)->arg_info,
sizeof(zend_arg_info)*(CG(active_op_array)->num_args));
@@ -1710,34 +1716,49 @@
static zend_bool zend_do_perform_implementation_check(zend_function *fe)
{
zend_uint i;
+ zend_function *proto = fe->common.prototype;
- if (!fe->common.prototype) {
+ if (!proto) {
return 1;
}
- if (fe->common.num_args != fe->common.prototype->common.num_args
- || fe->common.pass_rest_by_reference !=
fe->common.prototype->common.pass_rest_by_reference) {
+ /* check number of arguments */
+ if (proto->common.num_args < fe->common.required_num_args
+ || proto->common.num_args > fe->common.num_args) {
+ return 0;
+ }
+
+ if (proto->common.pass_rest_by_reference
+ && !fe->common.pass_rest_by_reference) {
return 0;
}
- if (fe->common.prototype->common.return_reference != ZEND_RETURN_REFERENCE_AGNOSTIC
- && fe->common.return_reference != fe->common.prototype->common.return_reference)
{
+ if (proto->common.return_reference != ZEND_RETURN_REFERENCE_AGNOSTIC
+ && fe->common.return_reference != proto->common.return_reference) {
return 0;
}
- for (i=0; i< fe->common.num_args; i++) {
- if (ZEND_LOG_XOR(fe->common.arg_info[i].class_name,
fe->common.prototype->common.arg_info[i].class_name)) {
+ for (i=0; i < proto->common.num_args; i++) {
+ if (ZEND_LOG_XOR(fe->common.arg_info[i].class_name, proto->common.arg_info[i].class_name))
{
/* Only one has a type hint and the other one doesn't */
return 0;
}
if (fe->common.arg_info[i].class_name
- && strcmp(fe->common.arg_info[i].class_name,
fe->common.prototype->common.arg_info[i].class_name)!=0) {
+ && strcmp(fe->common.arg_info[i].class_name,
proto->common.arg_info[i].class_name)!=0) {
return 0;
}
- if (fe->common.arg_info[i].pass_by_reference !=
fe->common.prototype->common.arg_info[i].pass_by_reference) {
+ if (fe->common.arg_info[i].pass_by_reference !=
proto->common.arg_info[i].pass_by_reference) {
return 0;
}
}
+
+ if (proto->common.pass_rest_by_reference) {
+ for (i=proto->common.num_args; i < fe->common.num_args; i++) {
+ if (!fe->common.arg_info[i].pass_by_reference) {
+ return 0;
+ }
+ }
+ }
return 1;
}
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.275&r2=1.276&ty=u
Index: ZendEngine2/zend_compile.h
diff -u ZendEngine2/zend_compile.h:1.275 ZendEngine2/zend_compile.h:1.276
--- ZendEngine2/zend_compile.h:1.275 Thu Feb 12 08:49:55 2004
+++ ZendEngine2/zend_compile.h Wed Feb 25 04:25:37 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.h,v 1.275 2004/02/12 13:49:55 zeev Exp $ */
+/* $Id: zend_compile.h,v 1.276 2004/02/25 09:25:37 zeev Exp $ */
#ifndef ZEND_COMPILE_H
#define ZEND_COMPILE_H
@@ -151,6 +151,7 @@
zend_uint fn_flags;
union _zend_function *prototype;
zend_uint num_args;
+ zend_uint required_num_args;
zend_arg_info *arg_info;
zend_bool pass_rest_by_reference;
unsigned char return_reference;
@@ -201,6 +202,7 @@
zend_uint fn_flags;
union _zend_function *prototype;
zend_uint num_args;
+ zend_uint required_num_args;
zend_arg_info *arg_info;
zend_bool pass_rest_by_reference;
unsigned char return_reference;
@@ -221,6 +223,7 @@
zend_uint fn_flags;
union _zend_function *prototype;
zend_uint num_args;
+ zend_uint required_num_args;
zend_arg_info *arg_info;
zend_bool pass_rest_by_reference;
unsigned char return_reference;
http://cvs.php.net/diff.php/ZendEngine2/zend_opcode.c?r1=1.101&r2=1.102&ty=u
Index: ZendEngine2/zend_opcode.c
diff -u ZendEngine2/zend_opcode.c:1.101 ZendEngine2/zend_opcode.c:1.102
--- ZendEngine2/zend_opcode.c:1.101 Fri Feb 20 01:59:37 2004
+++ ZendEngine2/zend_opcode.c Wed Feb 25 04:25:37 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_opcode.c,v 1.101 2004/02/20 06:59:37 sniper Exp $ */
+/* $Id: zend_opcode.c,v 1.102 2004/02/25 09:25:37 zeev Exp $ */
#include <stdio.h>
@@ -74,6 +74,7 @@
op_array->arg_info = NULL;
op_array->num_args = 0;
+ op_array->required_num_args = 0;
op_array->scope = NULL;