php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47416 Please add "endclass", "endfunction" keywords.
Submitted: 2009-02-17 00:18 UTC Modified: 2009-02-17 15:41 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: mail at dropdev dot org Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 6CVS-2009-02-17 (CVS) OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mail at dropdev dot org
New email:
PHP Version: OS:

 

 [2009-02-17 00:18 UTC] mail at dropdev dot org
Description:
------------
Note: I'm aware of the "won't fix" on #24100

I'm re-requesting this feature, because this syntax actually helps people working with php to debug their program.

Consider this:
When using curly braces, PHP gives an syntax error at the end of the file, on a non-existing line (which confuses developpers), using an item ($end) which looks like a php variable (which confuses developpers even more).
Also, the error message confuses lot's of developpers as can be seen in the loads of issues popping on when searching for the error.

Now consider this:
When using endxxx statements, it gives a more meaningful, error message, which is also a lot closer to the actual error position (a bless if you have 1000+ lines of code in your difficult class)
Also, it is much easier to search for in the documentation (see: http://php.net/manual/tokens.php which is on the first page of the search, if you search sitewide for T_ENDFOREACH)

As a free bonus, using this alternative syntax also resolves the ongoing discussion on where to place the curly braces (new line/no new line).

please also read: http://www.geocities.com/tablizer/endx.htm

The reproduce code contains two similar independent examamples showing the primary and alternative syntax, each with 1 syntax error to show the difference between the both.

Reproduce code:
---------------
<?php
// example 1
$foobar = array('foo', 'bar');
if (TRUE):
  if (TRUE):
    foreach($foobar as $key => $value):
      if (TRUE):
        // some code
      // also code
    endforeach; // << syntax error here!!! (unexpected T_ENDFOREACH)
  endif;
else:
  // more code
endif;

// example 2
$foobar = array('foo', 'bar');
if (TRUE) {
  if (TRUE) {
    foreach($foobar as $key => $value) { 
      if (TRUE) {
        // some code...
      // also code...
    }
  }
} else {
  // more code ...
}
// << syntax error here!!! (unexpected $end)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-17 15:41 UTC] johannes@php.net
Derick'S response to #24100 is still valid. We still prefer the {} syntax.

 [2012-02-27 13:46 UTC] undsoft at gmail dot com
Hi,

I'd like to speak in favour of the request.

Alternative syntax is very useful for embedding php code to the html.
This way statements like <?php endif ?> look pretty much like template engine tags.

Very useful in php framework's view files.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC