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


Groups > comp.lang.php > #14560

Re: OO PHP result of new if a constructor fails

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: OO PHP result of new if a constructor fails
Date 2014-11-13 14:11 +0100
Organization solani.org
Message-ID <m42aln$t2l$1@solani.org> (permalink)
References (1 earlier) <4146385.JyWBYEY6r6@PointedEars.de> <m3uevr$s4b$1@solani.org> <2544086.7FOxZRQfaF@PointedEars.de> <m40t74$pi6$1@solani.org> <2482034.fQki01Cq4G@PointedEars.de>

Show all headers | View raw


Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
> 
>> Thanks.  I am aware of that (unfortunately, I'm still having to cope
>> with PHP 4 compatible code).  I attempted (and failed) to make the
>> distinction between a function vs. an object-creation-expression[1]
>> being called constructor, the latter obviously "returning" something.
> 
> This distinction is invalid as an /object-creation-expression/ is never 
> referred to as a “constructor” in the first place, [...]

Some people might wrongly consider an /object-creation-expression/ as
being the constructor.  I just wanted to clarify.

> BTW, I am not certain whether this specification should be considered 
> authoritative:
> 
> <https://github.com/php/php-langspec/blob/master/LICENSE>,
> but: <https://github.com/php/php-langspec/blob/master/README.md>

The PHP developers seem to consider the specification authoritative, see
e.g. <http://news.php.net/php.internals/78871>f.

>> ACK.  However, you could call a constructor function dynamically, e.g.
>>
>>   $this->__construct();
> 
> Yes, but that is a) a bit pointless as the instance had to be constructed 
> first (so that $this refers to it) and b) rather careless because 
> constructors are usually designed to call other methods for initialization, 
> whereas this call could only be contained in an “other method”, potentially 
> leading to infinite recursion.

ACK.

>> AFAIK, the behavior of ECMAScript is rather uncommon, but quite useful
>> (especially wrt. calling the constructor function without new), but can
>> be simulated in PHP with static factory methods and (a) private
>> constructor(s).
> 
> No.

Why not?

-- 
Christoph M. Becker

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


Thread

OO PHP result of new if a constructor fails "James Harris" <james.harris.1@gmail.com> - 2014-11-11 15:13 +0000
  Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-11 10:20 -0500
    Re: OO PHP result of new if a constructor fails "James Harris" <james.harris.1@gmail.com> - 2014-11-11 15:56 +0000
      Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-11 11:03 -0500
        Re: OO PHP result of new if a constructor fails "James Harris" <james.harris.1@gmail.com> - 2014-11-11 16:27 +0000
          Re: OO PHP result of new if a constructor fails Matthew Carter <m@ahungry.com> - 2014-11-11 12:01 -0500
            Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-11 12:56 -0500
          Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-11 12:52 -0500
  Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-11 18:12 +0100
  Re: OO PHP result of new if a constructor fails Richard Damon <Richard@Damon-Family.org> - 2014-11-11 13:03 -0500
  Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-11 23:54 +0100
    Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-12 03:00 +0100
      Re: OO PHP result of new if a constructor fails Matthew Carter <m@ahungry.com> - 2014-11-11 22:25 -0500
        Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-11 22:36 -0500
          Re: OO PHP result of new if a constructor fails Matthew Carter <m@ahungry.com> - 2014-11-12 01:30 -0500
            Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-12 07:08 -0500
            Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-12 13:30 +0100
              Re: OO PHP result of new if a constructor fails Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-12 13:52 +0000
                Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 00:46 +0100
                Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-12 22:28 -0500
      Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-12 21:30 +0100
        Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 01:15 +0100
          Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 04:09 +0100
            Re: OO PHP result of new if a constructor fails Stefan+Usenet@Froehlich.Priv.at (Stefan Froehlich) - 2014-11-13 07:42 +0000
            Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 14:11 +0100
              Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 21:40 +0100
                Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-14 13:49 +0100
                Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-14 23:25 +0100
          Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-12 22:29 -0500
            Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 21:45 +0100
              Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-13 15:56 -0500
                Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 22:09 +0100
                Re: OO PHP result of new if a constructor fails Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-13 21:03 -0500
              Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-13 22:47 +0100
                Re: OO PHP result of new if a constructor fails Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-13 22:59 +0100
                Re: OO PHP result of new if a constructor fails "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-11-18 19:02 +0100

csiph-web