Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116183 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83018 invoked from network); 27 Sep 2021 16:02:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Sep 2021 16:02:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 84FE1180539 for ; Mon, 27 Sep 2021 09:44:49 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 27 Sep 2021 09:44:49 -0700 (PDT) Received: by mail-pj1-f49.google.com with SMTP id u1-20020a17090ae00100b0019ec31d3ba2so4638112pjy.1 for ; Mon, 27 Sep 2021 09:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sphaqmEYuJaCuDOuntOwPY8V5/SUTDEkIJTLeDMScXw=; b=a9eR742HGYuahau/2NfwCki4J1JHNrHEAaDZ5PI7m4ZCOkIF5F7rrShfPgu//Gbxky mjrzyFPHB09ocbrOv4zOx/uP0AIp14Kv0d6dciUMOtzOMt63tV6DduwoSXon3gtfAIQn 6syvXWzhjTiD3YCHOqftDYEQDwK+xKdnCKAP9wDnAAdyDgYjn0d/cdizKXBwvkZsnoXk N2eg0D2P8FqupbKUMVmkwlEFRf7wTki2ohud+xqGBYil9YPZg/BbweaNBkD+y7bZTZrQ EE3Fu2IrOfb8QtL7vb/xVwWursyifADrBP29fC2JexAWTVJ4Khmn+DbhZFvjKDptS9Nm Hppg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sphaqmEYuJaCuDOuntOwPY8V5/SUTDEkIJTLeDMScXw=; b=ovOJEvBvbdNEnJ6gZqhu6eEv88QGW9JEi9mAZCHabvjoa1yHr95cqAlo3depzlx14K FEtsTZiuxuM3ryh4Skti8gnZl+eBchIv5u03P5yZfSefwHF3gg8q5NXqiqYJbRTzJOAz H9Z6H2SKO0iXoPmZspbdmy9Wr3gVh19XU6MoLplpN/Vkr9c3VDz4SajtGERJQ/nwZ1dY PyDscSeL+E4zJQsNmI3M5e/vtihNEQF0wNU+ps3byVEjcmLFDyQoeCvKZWj9eJZIPPvk 3lRsrUIiUXd3rZ387o226HDk+rNJBhPAI5IfR8UsTo+GK95fjeEDkbVw6hUI4tYBU5qT SCtA== X-Gm-Message-State: AOAM531jBUVnxhwENOLDE3osq8ku3sOeGRM/jXDk3sSsFmIdB5mlqlMb uA67B6jnMe9ITkPdQV2hV5HVQT3+Q5Ona/O60ogw6Q== X-Google-Smtp-Source: ABdhPJzgyKCr0L5FrS/gyqXgJM3GQeooYNofPHf5hJ8xNDwP366G9t4wHhUKNX1u++pAqV0szYQrksozfRSQnG7rquE= X-Received: by 2002:a17:90a:19d2:: with SMTP id 18mr31505pjj.27.1632761087200; Mon, 27 Sep 2021 09:44:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 27 Sep 2021 18:44:36 +0200 Message-ID: To: Levi Morrison Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Static (factory) methods in attributes and initializers From: andreas@dqxtech.net (Andreas Hennings) Hello Levi, I thought it was clear. By static "factory" method I just mean any static method that returns an object. Don't interpret too much into the term :) So to clarify, here is an example: class OtherAttribute {} class MyAttribute { public function __construct(string $name) {..} #[Attribute] public static function create(string $name): self { return new self($name); } #[Attribute] public static function createOther($x): OtherAttribute { return new OtherAttribute($x); } } class SomeValue { public static function create() {return new self();} } #[MyAttribute::create('hello')] #[MyAttribute::createOther(SomeValue::create())] class C {} // This is the other part, static method calls in regular initializers. function f($x = SomeValue::create()) Things to observe: - The classes MyAttribute and OtherAttribute are not marked as attribute via #[Attribute] annotation. Only the static methods are. - MyAttribute::create() and MyAttribute::createOther() are allowed to return any object that they want. On Mon, 27 Sept 2021 at 18:26, Levi Morrison via internals wrote: > > I'm not exactly sure what you are proposing. However, it's always > worth noting other languages which have something in the feature > space, and Dart has both named constructors and factory constructors. > You should start with researching what they do, and what other > languages may have the same as _language features_, and not as > patterns e.g. Java has a factory pattern, but it's not part of the > language (at least not that I last checked, I don't follow Java). > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >