Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126101 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id D5C4B1A00BD for ; Wed, 4 Dec 2024 17:41:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1733333928; bh=XuLQsxEoYbNKbfhgkI5Vigfd0IswXUdvH+mxj5DF6Xw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=FzAOoIPb5tlzI87IlmvA7UmcqwwUPsoqcaPJDGKcbUQ1++KxgcPFrLf4ZUI4r5/AP MfXitbYHYXrRErjPS5/+o0HUXx9b8tC1b25EyVs1KLsklS8DKHALUqnqPk5u7Uji3/ zPF9lFv+p+cfL9W1gH5tfFbPNvdgLifi5OWpzeQ2KhYoPQJw5WcDZsR7p3F37i2ajO Ym+VEznCdTv3LIsv9pOau9E6jXJyEHET0lvYtS5zPBce7XzLhvtLnik1/1HCOMCbKm qtpIeJAiDznhky5CtWvjHy/iiwPW4XYkWNPRVkZR/OHpj71lr5ki4vH5kMrfHDgcdL 7627BIYVsP/7A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 55BBC180042 for ; Wed, 4 Dec 2024 17:38:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 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 X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 4 Dec 2024 17:38:44 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2eed82ca5b4so67536a91.2 for ; Wed, 04 Dec 2024 09:41:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733334111; x=1733938911; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bYClneF4zNRxwREDScHn1GY1m6WITTh+UBFlcb+5qeo=; b=FjTg/KGqmRKyxg1xWGXh2NKD/r69LWVNTWIjrW8sbe7YbF7Da7TCmdNto6jLM+1cCd RBXDvNCqTKeBXrBa7lKwKb92aXGrA20zCB154+Bb5wW/bb4APWerBua7HoKVhWtt8j4y PZqt0N2nD5ZDIXG0Hv1gX/KJcEqG3lcuqep/PxfVzdDfNxJGvS0lFe3E08oymJSdNGQK cCil/1HFt0eFBp1tlwsiESTOuchhSrXsp6jQO54kTc+hglREyECncivKcROzZyWq+7ha JFLhJL7WViAzxjmdfofKZfTuoF/qsHitlo8Oon7iU7gAb2wpZCkOVwr5BDx3zjI+0Ypu O9Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733334111; x=1733938911; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bYClneF4zNRxwREDScHn1GY1m6WITTh+UBFlcb+5qeo=; b=nurFHhOgNL0EIoCFe1B1Adeb8HxbDt9vp7qTOsvFEUtymcCvmrLRfHLRWd6YxIZAAu HOCdd5z1usaj443uPwp2Lfar8mf4ZZdvTLb1N5l11oMyIqeEr1sVmQ+thvM/3NUX1+hM 7FBtiXsVLmIXhxlub53aMz44VItowl6yAEGdC6gSqaNNWtCfMNVl2VSDEyC8p5ltOgJz nNRNOtCCPyiCzw1tp9ul0SXtfdIOm0eheaU2ZXyCSVW1ecxgPNFMoVshlAYGSRJsm2bp m8ekPMDWssS8L65T6791E/akIWD0ZG0UvWNJF07AbYj7JOWOIMcwWtzGdgw0WBLpO58/ aqJQ== X-Forwarded-Encrypted: i=1; AJvYcCVnyJEmJ1D3LT9cCGw2WzSpi10GQNphz7+cVHt+oydQr727Hj12gFN2AjkebSdVxOXsPa4MSKWiUWQ=@lists.php.net X-Gm-Message-State: AOJu0Yxb5ISaDPU6kowzmrVAWICx7QuDVU48SIbLiK5t43U5WSkzdgGh SPqtUiuYYIwX/upARiEXRODrZ3LTEPclMXu4Lu33k0kFcyccDiqys8NbVmsAYOCnxDypCNnolsx /OLRfTdwb8TbvI6DgbXIp/jQWMhI= X-Gm-Gg: ASbGncv2PNVOn+avgNy/vX+Jwgt6lq7iuOmqyNkT2QRoaz+tYPXhJgb/TplMGYoaQHu Zyp1F9GeOXmvWdRg0Zz6IiAKvFxKYrxk= X-Google-Smtp-Source: AGHT+IE6scbkqzuNZo0clZbAveO82lOe7xPQZXm28enqhHbRdc/P/ouzn8pLhi73Cm1MglIErWcdLADXzB8wTCibSzo= X-Received: by 2002:a17:90a:d450:b0:2ee:d96a:5831 with SMTP id 98e67ed59e1d1-2ef01259f11mr11120227a91.30.1733334111201; Wed, 04 Dec 2024 09:41:51 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Dec 2024 14:41:40 -0300 Message-ID: Subject: Re: [PHP-DEV] Multiple property assigning without constructor To: Erick de Azevedo Lima Cc: Taras Chornyi , internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: carlosv775@gmail.com (Vinicius Dias) > But often classes need constructors only to set properties. In such cases, constructors become redundant. Actually, the behavior is not the same and the constructors are not redundant. Taking your example: ``` class Person { public string $firstName; public int $age; } $person = new Person { firstName: "John", age: 42 }; ``` This would allow the following: ``` $invalidPerson = new Person(); ``` Now we have a person without name or age. But with constructors we make sure that the object is always in a valid state: ``` class Person { public function __construct(public string $firstName, public int $age) { } } $validPerson = new Person('Name', 40); $invalidPerson = new Person(); // this is impossible. every person needs firstName and age ``` I just wanted to point that out. :-)