Skip to content

Add deprecated userspace functions #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Zend/tests/deprecated_functions_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Declare deprecated function
--FILE--
<?php

deprecated function a() {
echo "Called\n";
}

a();

?>
--EXPECTF--
Deprecated: Function a() is deprecated in %sdeprecated_functions_001.php on line 7
Called
17 changes: 17 additions & 0 deletions Zend/tests/deprecated_functions_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Declare deprecated method
--FILE--
<?php

class MyClass {
deprecated public static function b() {
echo "Called\n";
}
}

MyClass::b();

?>
--EXPECTF--
Deprecated: Function MyClass::b() is deprecated in %sdeprecated_functions_002.php on line 9
Called
16 changes: 16 additions & 0 deletions Zend/tests/deprecated_functions_003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Disallow multiple deprecated modifiers
--FILE--
<?php

class MyClass {
deprecated public static deprecated function b() {
echo "Called\n";
}
}

MyClass::b();

?>
--EXPECTF--
Fatal error: Multiple deprecated modifiers are not allowed in %sdeprecated_functions_003.php on line 4
18 changes: 18 additions & 0 deletions Zend/tests/deprecated_functions_004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Disallow deprecated properties
--FILE--
<?php

class MyClass {
deprecated public $a = 7;

public function b() {
echo "Called\n";
}
}

MyClass::b();

?>
--EXPECTF--
Fatal error: Properties cannot be declared deprecated in %sdeprecated_functions_004.php on line 4
19 changes: 15 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,10 @@ int zend_do_verify_access_types(const znode *current_access_type, const znode *n
&& (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_FINAL)) {
zend_error(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
}
if ((Z_LVAL(current_access_type->u.constant) & ZEND_ACC_DEPRECATED)
&& (Z_LVAL(new_modifier->u.constant) & ZEND_ACC_DEPRECATED)) {
zend_error(E_COMPILE_ERROR, "Multiple deprecated modifiers are not allowed");
}
if (((Z_LVAL(current_access_type->u.constant) | Z_LVAL(new_modifier->u.constant)) & (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) == (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) {
zend_error(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member");
}
Expand All @@ -1529,7 +1533,7 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
char *name = function_name->u.constant.value.str.val;
int name_len = function_name->u.constant.value.str.len;
int function_begin_line = function_token->u.op.opline_num;
zend_uint fn_flags;
zend_uint fn_flags = 0;
const char *lcname;
zend_bool orig_interactive;
ALLOCA_FLAG(use_heap)
Expand All @@ -1541,10 +1545,13 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
}
Z_LVAL(fn_flags_znode->u.constant) |= ZEND_ACC_ABSTRACT; /* propagates to the rest of the parser */
}
fn_flags = Z_LVAL(fn_flags_znode->u.constant); /* must be done *after* the above check */
} else {
fn_flags = 0;
/*fn_flags = Z_LVAL(fn_flags_znode->u.constant); /* must be done *after* the above check */
}

if(fn_flags_znode) {
fn_flags = Z_LVAL(fn_flags_znode->u.constant);
}

if ((fn_flags & ZEND_ACC_STATIC) && (fn_flags & ZEND_ACC_ABSTRACT) && !(CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE)) {
zend_error(E_STRICT, "Static function %s%s%s() should not be abstract", is_method ? CG(active_class_entry)->name : "", is_method ? "::" : "", Z_STRVAL(function_name->u.constant));
}
Expand Down Expand Up @@ -5404,6 +5411,10 @@ void zend_do_declare_property(const znode *var_name, const znode *value, zend_ui
CG(active_class_entry)->name, var_name->u.constant.value.str.val);
}

if (access_type & ZEND_ACC_DEPRECATED) {
zend_error(E_COMPILE_ERROR, "Properties cannot be declared deprecated");
}

if (zend_hash_find(&CG(active_class_entry)->properties_info, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, (void **) &existing_property_info)==SUCCESS) {
zend_error(E_COMPILE_ERROR, "Cannot redeclare %s::$%s", CG(active_class_entry)->name, var_name->u.constant.value.str.val);
}
Expand Down
11 changes: 7 additions & 4 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%}

%pure_parser
%expect 3
%expect 6

%token END 0 "end of file"
%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE
Expand Down Expand Up @@ -167,13 +167,14 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%token T_USE "use (T_USE)"
%token T_INSTEADOF "insteadof (T_INSTEADOF)"
%token T_GLOBAL "global (T_GLOBAL)"
%right T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC
%right T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC T_DEPRECATED
%token T_STATIC "static (T_STATIC)"
%token T_ABSTRACT "abstract (T_ABSTRACT)"
%token T_FINAL "final (T_FINAL)"
%token T_PRIVATE "private (T_PRIVATE)"
%token T_PROTECTED "protected (T_PROTECTED)"
%token T_PUBLIC "public (T_PUBLIC)"
%token T_DEPRECATED "deprecated (T_DEPRECATED)"
%token T_VAR "var (T_VAR)"
%token T_UNSET "unset (T_UNSET)"
%token T_ISSET "isset (T_ISSET)"
Expand Down Expand Up @@ -375,7 +376,7 @@ is_reference:


unticked_function_declaration_statement:
function is_reference T_STRING { zend_do_begin_function_declaration(&$1, &$3, 0, $2.op_type, NULL TSRMLS_CC); }
function is_reference T_STRING { zend_do_begin_function_declaration(&$1, &$3, 0, $2.op_type, &$1 TSRMLS_CC); }
'(' parameter_list ')'
'{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); }
;
Expand Down Expand Up @@ -677,6 +678,7 @@ member_modifier:
| T_STATIC { Z_LVAL($$.u.constant) = ZEND_ACC_STATIC; }
| T_ABSTRACT { Z_LVAL($$.u.constant) = ZEND_ACC_ABSTRACT; }
| T_FINAL { Z_LVAL($$.u.constant) = ZEND_ACC_FINAL; }
| T_DEPRECATED { Z_LVAL($$.u.constant) = ZEND_ACC_DEPRECATED; }
;

class_variable_declaration:
Expand Down Expand Up @@ -832,7 +834,8 @@ combined_scalar:
| '[' array_pair_list ']' { $$ = $2; }

function:
T_FUNCTION { $$.u.op.opline_num = CG(zend_lineno); }
T_DEPRECATED T_FUNCTION { $$ = $2; $$.u.op.opline_num = CG(zend_lineno); Z_LVAL($$.u.constant) = ZEND_ACC_DEPRECATED; }
| T_FUNCTION { $$.u.op.opline_num = CG(zend_lineno); Z_LVAL($$.u.constant) = 0; }
;

lexical_vars:
Expand Down
Loading