Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126376 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 71A651A00BC for ; Tue, 11 Feb 2025 21:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739309396; bh=eeBIit+CTAipG1aUUjK7PXsNsebpxAX25F9y9sBRgL4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YHjZ88Ovgi8seaPGPfEYUN0GxH1XKEqrldODviNd9Wz6LuILOT8fNsT/bQTg6HvYU FCHCGxXxRYRZLFWYK/3bfThdCUhKPaj2ifuMfpLV2X2zlrUfSYnsdJ6BVH3SGj9VSS h7wUgd1n1Ne9DIIZVUkutI7Z58jXrftptYsEHsC5F8y82ubci8iEQHAvGBsRFgyc9l j+pA5/EKS/JRe57qrp/GKqRtpqMyUWo0OkSzviqKPxO1RIIzFIg4R/0x5PcMgyr+y6 Nsghzqr4CVwJjU0i3ouU4IckfOsoVQ/lA938QxK6fOqd4BaLiNV7f0R9fhG3ecpxHD HW2dmKXGy1UUg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5D9741801E5 for ; Tue, 11 Feb 2025 21:29:52 +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.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_INVALID,DKIM_SIGNED,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,T_SPF_TEMPERROR,URIBL_SBL_A autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (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 ; Tue, 11 Feb 2025 21:29:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1739309552; cv=none; d=zohomail.com; s=zohoarc; b=ID9SkQ+/fSmYVVEys2qoS9n6HILHxdLknsSJnkvlA4LsFwBBStERI6H0hB0XC3cROzS9OSIgy3J53TZbYaAVCufUDS8YIAGx6n7wU29QJWbIYgna4Xpu8welQSjEp8IvLV0y15j2Q+JKUzY+wtKOhPdzrYPHDYlDdTyhNSIOfdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739309552; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=eeBIit+CTAipG1aUUjK7PXsNsebpxAX25F9y9sBRgL4=; b=RAwM5FXMwSsPociznlxfVX+l8gzJMLLBOPY6TThaR2F0ahzzaK7W/Jq17DKdKv5uK18GER9DGwcTRsLcRdYHNaoMSxKHXmwqFE9ysdMYVp1iaxhTKQEUZRv1OHvh4/BQOVppmwRYZ1luqKXVPcRNi0MXWMrCbtHCCt0lt0ojnpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=faizanakram.me; spf=pass smtp.mailfrom=hello@faizanakram.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739309552; s=zoho; d=faizanakram.me; i=hello@faizanakram.me; h=MIME-Version:References:In-Reply-To:From:From:Date:Date:Message-ID:Subject:Subject:To:To:Cc:Cc:Content-Type:Message-Id:Reply-To; bh=eeBIit+CTAipG1aUUjK7PXsNsebpxAX25F9y9sBRgL4=; b=CEY8DJ88jx/ez1zcvt1OsZBC0Tz8Id/FmHlGm0hke8uuHhuK4IxFVmRAzLeRIwz9 D8tfgSrLNm7LhZcTvZxTGffamnquZ9/f0uN9QV5pt+6twvTnp9RvZz9DQzCLE5Zw87j I7+3Dd3F8n9J3ius1SEk6u8v6CluqHr1jLNxG9Yo= Received: by mx.zohomail.com with SMTPS id 1739309547326625.6384729806952; Tue, 11 Feb 2025 13:32:27 -0800 (PST) Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-e5372a2fbddso5000293276.3 for ; Tue, 11 Feb 2025 13:32:27 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCU7SX/SEUlbXVbEhvNcanK2ncQzh5iOndJwwp9Sy5JvHUlbleuV95nHtYu+CHlr3QyDfI6cmuHPlPY=@lists.php.net X-Gm-Message-State: AOJu0YxKjSGcNHBb24a6DRwaDhilE2mfXBKCt6vVo1+IRu5LaUGJ/2p9 it0+XDJt+YRlGY77n8iEq6P4wvEpcjw0j0OLPUGnvbUSFXqtCmt08OYU/yIpJbsS2si1QdFXzu8 3ffUJmfKNzD7IM5bRaBu6g98Z9Z0= X-Google-Smtp-Source: AGHT+IFHMY2fomfS8SD0QfFS0lUFR18cRCq45/vkOyVvtSThCpLPLzctfafwQDsM5eW+pL+GOszgFY4mII1WsIkOSXQ= X-Received: by 2002:a05:6902:1548:b0:e5a:e88e:b2cc with SMTP id 3f1490d57ef6-e5d9f187788mr1155912276.45.1739309546845; Tue, 11 Feb 2025 13:32:26 -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: Tue, 11 Feb 2025 22:32:15 +0100 X-Gmail-Original-Message-ID: X-Gm-Features: AWEUYZmC96mfZDdD3NrEU10UgP_KttwcL35SL7BdOAP6UOA0bxXU9m6SrjXrnuM Message-ID: Subject: Re: [PHP-DEV] RFC: Not Null Assertion Operator To: Valentin Udaltsov Cc: Mihail Liahimov <91liahim@gmail.com>, PHP internals Content-Type: multipart/alternative; boundary="000000000000b1c8c9062de48f6d" X-ZohoMailClient: External From: hello@faizanakram.me (Faizan Akram Dar) --000000000000b1c8c9062de48f6d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 11 Feb 2025, 17:07 Valentin Udaltsov, wrote: > > > Static analysis already complain about it > > That's exactly where `!` is helpful. If at a certain point I am sure that > a property must not be null and I want to make that explicit (to both > developer and static analyzer), I can use > `assert($obj->prop !=3D=3D null)`. However, that requires an extra line o= f > code. `$obj->prop!->x` would be much prettier. > > -- > Valentin > Hi Valentin, I still don't see the added value. PHP isn't Java=E2=80=94there are no hidd= en null pointer exceptions. Accessing a property on null triggers a runtime warning, and static analysis already flags it. It=E2=80=99s better if PHP t= hrows an error in such cases, as it does when calling methods on null. Since types don=E2=80=99t include null by default, and assigning null to a = typed property already throws an error, I don=E2=80=99t think an additional opera= tor is necessary. Best, Faizan > --000000000000b1c8c9062de48f6d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, 11 Feb 2025, 17:= 07 Valentin Udaltsov, <ud= altsov.valentin@gmail.com> wrote:
=C2=A0
> Static analys= is already complain about it

That's exactly where `!` is helpful= . If at a certain point I am sure that a property must not be null and I wa= nt=C2=A0to make=C2=A0that explicit (to both developer and static analyzer),= I can use
`assert($obj->prop !=3D=3D null)`. However, that re= quires an extra line of code. `$obj->prop!->x` would=C2=A0be much pre= ttier.

--
Valentin

Hi Valentin,

<= div dir=3D"auto">I still don't see the added value. PHP isn't Java= =E2=80=94there are no hidden null pointer exceptions. Accessing a property = on null triggers a runtime warning, and static analysis already flags it. I= t=E2=80=99s better if PHP throws an error in such cases, as it does when ca= lling methods on null.

S= ince types don=E2=80=99t include null by default, and assigning null to a t= yped property already throws an error, I don=E2=80=99t think an additional = operator is necessary.

B= est,
Faizan
--000000000000b1c8c9062de48f6d--