Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #16883

Re: Order of class definitions within the same file

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: Order of class definitions within the same file
Date 2016-07-27 18:06 +0200
Organization solani.org
Message-ID <nnam6a$u5b$1@solani.org> (permalink)
References <nn21eo$dmq$1@news.albasani.net> <nn8p5j$m6l$1@solani.org> <nnai3s$l47$1@news.albasani.net>

Show all headers | View raw


On 27.07.2016 at 16:57, Thomas Mlynarczyk wrote:

> I still don't quite understand it. In the second example (C-A-B), the
> executer notices that C is marked as incomplete, because of the parent
> B. So it looks for B and finds it. In the first case (C-B-A), it's the
> same, but B is marked as incomplete as well -- so why does the executor
> give up instead of simply doing another "level" of look-up? This must
> have been a deliberate decision made by the programmers.

There are cases which can't be resolved, at least mutual and circular
inheritance (A extends B, B extends A).  Not doing further lookup might
just be a simplification to avoid tracking such cycles.

Anyhow, I found that your second example already works as of PHP 4.3 at
least, see <https://3v4l.org/2DJJh>.  However, the respective manual
section has only been added in 2010[1], to resolve
<https://bugs.php.net/bug.php?id=51381>, which also notes that there are
exceptions from the rule "declare parent before child", which have not
been addressed.  Interestingly, there is another bug report with regard
to this very issue: <https://bugs.php.net/bug.php?id=70800>.

I suppose we'd need to ask Zend engine developers about the details.
internals@lists.php.net might be a good place to reach these.

> Indeed, as Jerry remarked, according to the manual, A-B-C is the only
> valid order and whether any other order works or not should be regarded
> as undocumented behaviour and hence not be relied upon.

ACK.

> […] Good programming practise
> requires you to put each class definition in a separate file. For
> distributing code, all files are sometimes combined into one. […]

Well, nowadays we may rely on OPcache (or another bytecode cache) to be
available, which solves the issue.  But I agree that combining in a
single file might still make sense.

[1] <http://svn.php.net/viewvc/?view=revision&amp;revision=304561>

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Order of class definitions within the same file Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2016-07-24 11:23 +0200
  Re: Order of class definitions within the same file "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-07-27 00:45 +0200
    Re: Order of class definitions within the same file Jerry Stuckle <jstucklex@attglobal.net> - 2016-07-26 23:15 -0400
    Re: Order of class definitions within the same file Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2016-07-27 16:57 +0200
      Re: Order of class definitions within the same file Jerry Stuckle <jstucklex@attglobal.net> - 2016-07-27 12:00 -0400
        Re: Order of class definitions within the same file Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2016-07-27 20:35 +0200
          Re: Order of class definitions within the same file "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-29 12:07 +0200
      Re: Order of class definitions within the same file "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-07-27 18:06 +0200
        Re: Order of class definitions within the same file Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2016-07-27 20:51 +0200

csiph-web