Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109316 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53230 invoked from network); 26 Mar 2020 03:07:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Mar 2020 03:07:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 343181804C6 for ; Wed, 25 Mar 2020 18:32:38 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS 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-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (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 ; Wed, 25 Mar 2020 18:32:37 -0700 (PDT) Received: by mail-oi1-f179.google.com with SMTP id t25so4122892oij.2 for ; Wed, 25 Mar 2020 18:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WgkIdMK3c1eR1AYNnk4BpAtz2FvGpjsxl7eMHul563Y=; b=dYBgyyn+kvz/TT8715uoiZJc8HGM49I5j9TI+LQoCZLJzMcj/cceU6lmuPRKyDon+G o+Ac8d8whf/uCHobNcFGZpavIaKAjI7aGNiUrUkt04Y7Mr5/FFTZEC+QgKW4RQQnP1kF 03b1pDbv3thN3ewOnCUqsvXDKkhobpp3N1zVzVgMZPBW7HepDbf1X5fbx/FPLFELX2ao I+mqAbdDkMReQVVSBeEbI/6Oz4hUmAt/xcL6rlaBul6aEAK7c/njGdcYWb8EWI9F+hb3 d3SKaLg35pOxkUxVjk+Cb59JEgSD/xTN61ocWcf0RX8stqXjLCDtiQ8DjGjG1pAn+iZm rBSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WgkIdMK3c1eR1AYNnk4BpAtz2FvGpjsxl7eMHul563Y=; b=YQvH1f4wle2FWsi1Re3uxuNyrqoeJpaNYxm3o5Q74kr+crrk6LhMSlHBp7+7oZ1sZj fMhvtRo3fqs1NoFid/8PwaVq6WfEcqN12zo1IaJ4h5+NKX1xNzMrhpabS1FQPt4P87Ad NuQA8eD97uQtOV0kVtPczkiu8C9rUPY+R8jh6Pf9r8Rc1WY8sNNFzsk/Q1yKAVRfSTp4 ubItOGlHEJ6/fx0s5eSjvx/CXcs2iolvHb2O1U+N8CgwVB1SkHY335LA0OtMPbKdlSlx E3t8PoGVq7ImahY0AF6yCb0yeDqOr0SXCJWVXG4UunqD6+BYvktUSkm8lpUCZIl0LmiV 0+Eg== X-Gm-Message-State: ANhLgQ1AX0UdYLky0H4KZ2Tf/gaM4aJU9uLPI9a8DzX2DPeyrACn4crS H0j8KIGEfusWWzz2wfqMGJx9Xz4lwWXGsvGSY5I= X-Google-Smtp-Source: ADFU+vu+5euVD86VuCpiLZQqFa04qJNh+pfBh7XRPwW5rz4bwYclmzP1jsD5KrJ3IGcZxiWofIKbh1Ag41LFaT0yhkw= X-Received: by 2002:aca:cf0d:: with SMTP id f13mr272940oig.162.1585186356260; Wed, 25 Mar 2020 18:32:36 -0700 (PDT) MIME-Version: 1.0 References: <306b173b-f104-1779-c75f-bbf8262631c4@gmail.com> In-Reply-To: <306b173b-f104-1779-c75f-bbf8262631c4@gmail.com> Date: Wed, 25 Mar 2020 22:32:24 -0300 Message-ID: To: Stanislav Malyshev Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000aaf4f605a1b7f554" Subject: Re: [PHP-DEV] Class cast From: david.proweb@gmail.com (David Rodrigues) --000000000000aaf4f605a1b7f554 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello! > What's wrong with new Number(123)? Actually it is a simplest case, where only a single information was considered. But you can expand it to something more complex, where currently you will need create a static method to copy the data, which is not a normalized way like cast could do. > Not sure why would you want to do this? What's the use case? You could mix the previous answer when arguments to a method that expects a Number, for instance: X::test((Number) $x). Or you can increase the type of information when possible. For instance: function requiresB(B $b); But you have only A $a. You can create: function __cast($value) { if ($value instanceof A) return B($value, 123, M_PI); } Then use: requiresB((B) $a); Atenciosamente, David Rodrigues Em qua., 25 de mar. de 2020 =C3=A0s 20:06, Stanislav Malyshev < smalyshev@gmail.com> escreveu: > Hi! > > > 1. Converting from A to B: > > > > $a =3D 123; > > $b =3D (Number) $a; // $b is now instanceof Number > > > > A instanceof Number will created based on $a value. > > What's wrong with new Number(123)? > > > 2. Reduce object type (I don't know the technical term): > > > > class A {} > > class B extends A {} > > > > $b =3D new B; > > $a =3D (A) $b; > > > > $a still is $b, but with "limited" access to A methods and properties. > > Not sure why would you want to do this? What's the use case? > -- > Stas Malyshev > smalyshev@gmail.com > --000000000000aaf4f605a1b7f554--