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


Groups > comp.lang.php > #14530 > unrolled thread

OO PHP result of new if a constructor fails

Started by"James Harris" <james.harris.1@gmail.com>
First post2014-11-11 15:13 +0000
Last post2014-11-18 19:02 +0100
Articles 16 on this page of 36 — 8 participants

Back to article view | Back to comp.lang.php


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#14550

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-12 21:30 +0100
Message-ID<2544086.7FOxZRQfaF@PointedEars.de>
In reply to#14541
Christoph M. Becker wrote:

> Thomas 'PointedEars' Lahn wrote:
>> James Harris wrote:
>>> I understand that PHP constructors cannot return anything
>> Doubtful.
> 
> AIUI, a PHP constructor is the method __construct, […]

A common misconception (which was discussed during the ZCE PHP 5.4 Exam 
Preparation Course because it is a common pitfall in the exam).

Before there was the magic __construct() method (introduced with PHP 5.0), 
constructors could only be defined by a method whose identifier was the same 
as the class name, with the added catch that the matching was case-
insensitive (as with all PHP functions).

For backwards compatibility, this is still supported in PHP 5.x (just tested 
with PHP 5.6.2-1 CLI on Debian GNU/Linux); however, the __construct() method 
takes precedence for non-namespaced classes, and with namespaced classes the 
old behavior is no longer supported since PHP 5.3.3 (I, too, was at least 
not consciously aware of the latter – you can never learn enough).

<http://php.net/manual/en/language.oop5.decon.php>

Ad-hoc test code to play with:

  // namespace N;

  class C
  {
    function __construct ()
    {
      echo 42 . "\n";
    }
    
    function C ()
    {
      echo 23 . "\n";
    }
  }

  new C();

You should observe that

  * in PHP 5.x,

    - “23” is printed if you comment out the __construct() definition and
      leave the namespace declaration commented out;

    - *if the PHP version is greater than or equal to 5.3.3*,
      nothing is printed if you comment out the __construct() definition
      *and* use the namespace declaration;

    - “42” is printed otherwise;

  * in PHP 4.x (with the namespace declaration commented out, because it is
    a syntax error there),

    - “23” should be printed if you do not comment out the X() definition;

    - nothing should be printed otherwise.

> and that does not create an object, but merely initializes it, so the
> constructor can be thought of as a command (opposed to a query), and as
> such would never return anything (at least when properly called within a
> /new/ statement).

Since PHP 5.3.x at the latest, it is no longer possible to call constructors 
statically except with parent::…() [1], as that results in “Fatal error: 
Non-static method … cannot be called statically …” − 

<http://stackoverflow.com/a/19303354/855543>

lead me to find it in “zend_vm_execute.h” of PHP 5.3, but not PHP 5.2:

<http://lxr.php.net/search?q=cannot+be+called+statically&defs=&refs=&path=%2FPHP_5_3%2F&hist=&project=PHP_5_3>
<http://lxr.php.net/search?q=cannot+be+called+statically&defs=&refs=&path=%2FPHP_5_2%2F&hist=&project=PHP_5_2>

Also, it would appear that when a method is called as a constructor (with 
the “new” keyword; in the aforementioned PHP 5.6 version – may also be 
different in previous versions), its return value is ignored even if it is a 
reference to an object.  [Because of that, a constructor that can also serve 
as a factory, as in ECMAScript, for example, appears to be impossible in 
PHP.]
 
-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14553

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2014-11-13 01:15 +0100
Message-ID<m40t74$pi6$1@solani.org>
In reply to#14550
Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
> 
>> Thomas 'PointedEars' Lahn wrote:
>>> James Harris wrote:
>>>> I understand that PHP constructors cannot return anything
>>> Doubtful.
>>
>> AIUI, a PHP constructor is the method __construct, […]
> 
> A common misconception (which was discussed during the ZCE PHP 5.4 Exam 
> Preparation Course because it is a common pitfall in the exam).

<snipped thorough explanation>

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.

>> and that does not create an object, but merely initializes it, so the
>> constructor can be thought of as a command (opposed to a query), and as
>> such would never return anything (at least when properly called within a
>> /new/ statement).
> 
> Since PHP 5.3.x at the latest, it is no longer possible to call constructors 
> statically except with parent::…() [1], as that results in “Fatal error: 
> Non-static method … cannot be called statically …” − 

ACK.  However, you could call a constructor function dynamically, e.g.

  $this->__construct();

> Also, it would appear that when a method is called as a constructor (with 
> the “new” keyword; in the aforementioned PHP 5.6 version – may also be 
> different in previous versions), its return value is ignored even if it is a 
> reference to an object.  [Because of that, a constructor that can also serve 
> as a factory, as in ECMAScript, for example, appears to be impossible in 
> PHP.]

See <http://3v4l.org/IO1qB> for an example of the behavior of several
PHP versions (they behave like your PHP 5.6.2-1).

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).

[1]
<https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#the-new-operator>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14554

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-13 04:09 +0100
Message-ID<2482034.fQki01Cq4G@PointedEars.de>
In reply to#14553
Christoph M. Becker wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Christoph M. Becker wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> James Harris wrote:
>>>>> I understand that PHP constructors cannot return anything
>>>> Doubtful.
>>> AIUI, a PHP constructor is the method __construct, […]
>> A common misconception (which was discussed during the ZCE PHP 5.4 Exam
>> Preparation Course because it is a common pitfall in the exam).
> 
> <snipped thorough explanation>
> 
> 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, and there cannot be a 
(user-defined) constructor without a /function-definition/:

<https://github.com/php/php-langspec/blob/master/spec/14-classes.md#constructors>

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>
 
>> Since PHP 5.3.x at the latest, it is no longer possible to call
>> constructors statically except with parent::…() [1], as that results in
>> “Fatal error: Non-static method … cannot be called statically …” −
> 
> 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.

>> Also, it would appear that when a method is called as a constructor (with
>> the “new” keyword; in the aforementioned PHP 5.6 version – may also be
>> different in previous versions), its return value is ignored even if it
>> is a reference to an object.  [Because of that, a constructor that can
>> also serve as a factory, as in ECMAScript, for example, appears to be
>> impossible in PHP.]
> 
> See <http://3v4l.org/IO1qB> for an example of the behavior of several
> PHP versions (they behave like your PHP 5.6.2-1).

Thanks, I will have a look at it later.

> 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.

> [1]
> <https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#the-new-operator>
 
-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14558

FromStefan+Usenet@Froehlich.Priv.at (Stefan Froehlich)
Date2014-11-13 07:42 +0000
Message-ID<1t54645fddi6616n3e8%sfroehli@Froehlich.Priv.at>
In reply to#14554
On Thu, 13 Nov 2014 04:09:08 Thomas 'PointedEars' Lahn wrote:
> > 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)

I once considered using such a construction for a __wakeup() call in
order to re-use the (quite complex) initialization code. However:

> [...] 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.

Infinite recursion was not the problem in my case, but the whole
construction looked extremely ugly to me - and there is no guarantee
that such calls won't be forbidden in future releases, so I found a
better solution for it.

Bye,

Stefan
 
-- 
http://kontaktinser.at/ - die kostenlose Kontaktboerse fuer Oesterreich
Offizieller Erstbesucher(TM) von mmeike

Stefan. Für entbehrliche Kessel, wenn die Kacke dampft!
(Sloganizer)

[toc] | [prev] | [next] | [standalone]


#14560

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2014-11-13 14:11 +0100
Message-ID<m42aln$t2l$1@solani.org>
In reply to#14554
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

[toc] | [prev] | [next] | [standalone]


#14567

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-13 21:40 +0100
Message-ID<14454844.m36nGyrlVr@PointedEars.de>
In reply to#14560
Christoph M. Becker wrote:

> 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 do not see any indication of that in this thread.

> I just wanted to clarify.

Hmmm.
 
>> 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.

I do not see the connection.  Wrong ID?

>>> 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?

Basically, because you cannot do the following in PHP and have a *D* 
instance referred by *both* ”o” *and* “o2”:

  function C ()
  {
    function D () {}

    return new D();
  }

  var o = new C();
  var o2 = C();

Your static factory method is a *different* function that you *cannot* 
invoke with “new” as well.  Therefore, it is not a proper _emulation_.

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14581

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2014-11-14 13:49 +0100
Message-ID<m44tp7$9l0$1@solani.org>
In reply to#14567
Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
> 
>> Thomas 'PointedEars' Lahn wrote:
>>> Christoph M. Becker wrote:

>> The PHP developers seem to consider the specification authoritative, see
>> e.g. <http://news.php.net/php.internals/78871>f.
> 
> I do not see the connection.  Wrong ID?

The messages are part of a larger thread; unfortunately, the web
interface doesn't seem to allow viewing by thread, but rather all
threads are interleaved.  The following message
<http://news.php.net/php.internals/78872> (what I wanted to indicate
with the trailing "f"), makes it a bit more clear.  The "spec" they're
mentioning, is the lang-spec (not the PHP manual).

>>>> 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?
> 
> Basically, because you cannot do the following in PHP and have a *D* 
> instance referred by *both* ”o” *and* “o2”:
> 
>   function C ()
>   {
>     function D () {}
> 
>     return new D();
>   }
> 
>   var o = new C();
>   var o2 = C();
> 
> Your static factory method is a *different* function that you *cannot* 
> invoke with “new” as well.  Therefore, it is not a proper _emulation_.

Indeed, it is not a proper *emulation* (thanks for the correction).
However, you can do the following:

    class D {}

    class C {
        static function create() {
            return new D();
        }
        private function __construct() {}
    }

    $o = C::create();
    $o2 = C::create();

IMHO, that comes quite close to the intention of returning an instance
of another class, when trying to create a certain class' instance.  If
PHP had nested classes (a respective RFC[1] has been withdrawn, though),
it would even come closer.  (For now D could be regarded as been
private, and documented as such, and maybe renamed to _D.)  The
possibility of creating an instance with or without /new/, seems to be
more of a technical detail.

[1] <https://wiki.php.net/rfc/nested_classes>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14583

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-14 23:25 +0100
Message-ID<1847362.sI8kzj7xTN@PointedEars.de>
In reply to#14581
Christoph M. Becker wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Christoph M. Becker wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> Christoph M. Becker wrote:
>>> The PHP developers seem to consider the specification authoritative, see
>>> e.g. <http://news.php.net/php.internals/78871>f.
>> I do not see the connection.  Wrong ID?
> 
> The messages are part of a larger thread; unfortunately, the web
> interface doesn't seem to allow viewing by thread, but rather all
> threads are interleaved.  […]

It's a PITA to read it (one long line), but I can see it now.  Thanks.
 
>> [comparison with ECMAScript] […] you cannot do the following in PHP and 
>> have a *D* instance referred by *both* ”o” *and* “o2”:
>> 
>>   function C ()
>>   {
>>     function D () {}
>> 
>>     return new D();
>>   }
>> 
>>   var o = new C();
>>   var o2 = C();
>> 
>> Your static factory method is a *different* function that you *cannot*
>> invoke with “new” as well.  Therefore, it is not a proper _emulation_.
> 
> Indeed, it is not a proper *emulation* (thanks for the correction).
> However, you can do the following:
> 
>     class D {}
> 
>     class C {
>         static function create() {
>             return new D();
>         }
>         private function __construct() {}
>     }
> 
>     $o = C::create();
>     $o2 = C::create();
> 
> IMHO, that comes quite close to the intention of returning an instance
> of another class, when trying to create a certain class' instance.  If
> PHP had nested classes (a respective RFC[1] has been withdrawn, though),

Too bad.  It can be done in another way, though (kids, don't try this at 
home):

$ php -r '

class C
{
  public static function create ()
  {
    return D::_create();
  }
}

final class D extends C
{
  private function __construct () {}
  
  protected static function _create ()
  {
    return new self();
  }
}

var_dump(C::create());

'
class D#1 (0) {
}

> it would even come closer.  (For now D could be regarded as been
> private, and documented as such, and maybe renamed to _D.)

D can still be instantiated without the use of C unless its constructor is 
not public.

> The possibility of creating an instance with or without /new/, seems to be
> more of a technical detail.

I do not think so.  The subject was the constructor, not some factory 
method.
 
-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14556

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-12 22:29 -0500
Message-ID<m418j7$l57$2@dont-email.me>
In reply to#14553
On 11/12/2014 7:15 PM, Christoph M. Becker wrote:
> Thomas 'PointedEars' Lahn wrote:
> 
>> Christoph M. Becker wrote:
>>
>>> Thomas 'PointedEars' Lahn wrote:
>>>> James Harris wrote:
>>>>> I understand that PHP constructors cannot return anything
>>>> Doubtful.
>>>
>>> AIUI, a PHP constructor is the method __construct, […]
>>
>> A common misconception (which was discussed during the ZCE PHP 5.4 Exam 
>> Preparation Course because it is a common pitfall in the exam).
> 
> <snipped thorough explanation>
> 
> 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.
> 
>>> and that does not create an object, but merely initializes it, so the
>>> constructor can be thought of as a command (opposed to a query), and as
>>> such would never return anything (at least when properly called within a
>>> /new/ statement).
>>
>> Since PHP 5.3.x at the latest, it is no longer possible to call constructors 
>> statically except with parent::…() [1], as that results in “Fatal error: 
>> Non-static method … cannot be called statically …” − 
> 
> ACK.  However, you could call a constructor function dynamically, e.g.
> 
>   $this->__construct();
> 
>> Also, it would appear that when a method is called as a constructor (with 
>> the “new” keyword; in the aforementioned PHP 5.6 version – may also be 
>> different in previous versions), its return value is ignored even if it is a 
>> reference to an object.  [Because of that, a constructor that can also serve 
>> as a factory, as in ECMAScript, for example, appears to be impossible in 
>> PHP.]
> 
> See <http://3v4l.org/IO1qB> for an example of the behavior of several
> PHP versions (they behave like your PHP 5.6.2-1).
> 
> 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).
> 
> [1]
> <https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#the-new-operator>
> 

Don't worry about "Pointed Head".  He often goes off on a tangent
completely unrelated to the question.

He can read - but he doesn't UNDERSTAND.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14568

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-13 21:45 +0100
Message-ID<3502855.TMe9Y0mTcu@PointedEars.de>
In reply to#14556
Jerry Stuckle wrote:

> On 11/12/2014 7:15 PM, Christoph M. Becker wrote:
>> Thomas 'PointedEars' Lahn wrote:
>> […]
> 
> Don't worry about "Pointed Head".  […]

ROTFL.  You are probably just out of his killfile, eager to return there: 
<news:lub5tu$k7f$3@solani.org>

Do you have a text macro for your abuse?

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14570

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-13 15:56 -0500
Message-ID<m435t4$904$1@dont-email.me>
In reply to#14568
On 11/13/2014 3:45 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
> 
>> On 11/12/2014 7:15 PM, Christoph M. Becker wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>> […]
>>
>> Don't worry about "Pointed Head".  […]
> 
> ROTFL.  You are probably just out of his killfile, eager to return there: 
> <news:lub5tu$k7f$3@solani.org>
> 
> Do you have a text macro for your abuse?
> 

The truth hurts, doesn't it?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14572

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-13 22:09 +0100
Message-ID<10048711.1UOzmatOAn@PointedEars.de>
In reply to#14570
Jerry Stuckle wrote:

> On 11/13/2014 3:45 PM, Thomas 'PointedEars' Lahn wrote:
>> Jerry Stuckle wrote:
>>> On 11/12/2014 7:15 PM, Christoph M. Becker wrote:
>>>> Thomas 'PointedEars' Lahn wrote:
>>>> […]
>>> Don't worry about "Pointed Head".  […]
>> ROTFL.  You are probably just out of his killfile, eager to return there:
>> <news:lub5tu$k7f$3@solani.org>
>> 
>> Do you have a text macro for your abuse?
> 
> The truth hurts, doesn't it?

Which truth?  That in you are still not getting that you are barking up the 
wrong tree here?  No, that does not hurt me at all. 

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14577

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-11-13 21:03 -0500
Message-ID<m43nsk$47m$1@dont-email.me>
In reply to#14572
On 11/13/2014 4:09 PM, the pedantic troll Thomas 'Pointed Head' Lahn wrote:
> Jerry Stuckle wrote:
> 
>> On 11/13/2014 3:45 PM, Thomas 'PointedEars' Lahn wrote:
>>> Jerry Stuckle wrote:
>>>> On 11/12/2014 7:15 PM, Christoph M. Becker wrote:
>>>>> Thomas 'PointedEars' Lahn wrote:
>>>>> […]
>>>> Don't worry about "Pointed Head".  […]
>>> ROTFL.  You are probably just out of his killfile, eager to return there:
>>> <news:lub5tu$k7f$3@solani.org>
>>>
>>> Do you have a text macro for your abuse?
>>
>> The truth hurts, doesn't it?
> 
> Which truth?  That in you are still not getting that you are barking up the 
> wrong tree here?  No, that does not hurt me at all. 
> 

The truth that "Pointed Head" is nothing more than a pedantic troll -
well known in several newsgroups.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#14573

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2014-11-13 22:47 +0100
Message-ID<m438tn$cgs$1@solani.org>
In reply to#14568
Thomas 'PointedEars' Lahn wrote:

> Jerry Stuckle wrote:
> 
>> On 11/12/2014 7:15 PM, Christoph M. Becker wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>> […]
>>
>> Don't worry about "Pointed Head".  […]
> 
> ROTFL.  You are probably just out of his killfile, eager to return there: 
> <news:lub5tu$k7f$3@solani.org>

Yes, because my Thunderbird didn't handle that right: threads with
replies from killfiled addresses were marked as having new messages, and
I was not able to unmark them.  I found that more annoying than scanning
over senseless messages from time to time.

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#14575

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-11-13 22:59 +0100
Message-ID<5716115.oSzd2E7zM9@PointedEars.de>
In reply to#14573
Christoph M. Becker wrote:

> […] my Thunderbird didn't handle that right: threads with replies from 
> killfiled addresses were marked as having new messages, and I was not able
> to unmark them.  I found that more annoying than scanning over senseless
> messages from time to time.

It has been a while since I used Thunderbird for news, but it should work
if you modify the killfile filter rule so that it marks the message as read 
first/instead.  (You can [help to] fix the bug, too, though. ;-))

HTH

-- 
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#14608

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2014-11-18 19:02 +0100
Message-ID<m4g1kb$l3a$2@solani.org>
In reply to#14575
Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
> 
>> […] my Thunderbird didn't handle that right: threads with replies from 
>> killfiled addresses were marked as having new messages, and I was not able
>> to unmark them.  I found that more annoying than scanning over senseless
>> messages from time to time.
> 
> It has been a while since I used Thunderbird for news, but it should work
> if you modify the killfile filter rule so that it marks the message as read 
> first/instead.

Thanks.  That makes sense.

-- 
Christoph M. Becker

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.php


csiph-web