Make T_FUNCTION in method declarations optional. View as Markdown

Inactive
Authors
Johannes Schlüter
Date
2010-11-27
Version
1.0
Source
wiki.php.net/rfc/optional-t-function

Discussions on the mailing list

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:54 UTC

Introduction

The purpose of this RFC is proposing to remove the requirement of T_FUNCTION keyword in method declarations if a visibility flag (T_PUBLIC,T_PROTECTED, T_PRIVATE, T_STATIC, T_ABSTRACT, T_FINAL) is given in a class, trait or interface declaration.

Syntax

It is proposed that this is valid code:

class Foo {
    const C = 42;
    private $var;
 
    public bar() {
        echo "Hello World";
    }
}
 
$foo = new Foo();
$foo->bar();

While technically possible this RFC suggests that the following shall NOT be valid for keeping the code readable:

class Foo {
    const C = 42;
    private $var;
 
    bar() {
        echo "Hello World";
    }
}
 
$foo = new Foo();
$foo->bar();

Patch

An initial patch can be found at http://schlueters.de/~johannes/php/zend_optional_t_function.diff

Changelog

1.0: Initial proposal (JS)