Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110959 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21431 invoked from network); 11 Jul 2020 23:26:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 23:26:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BFA4B180510 for ; Sat, 11 Jul 2020 15:17:47 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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-Virus: No X-Envelope-From: Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) (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 ; Sat, 11 Jul 2020 15:17:47 -0700 (PDT) Received: by mail-io1-f44.google.com with SMTP id l1so9722323ioh.5 for ; Sat, 11 Jul 2020 15:17:47 -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=QNCUWJS54liesdignQo1OlFCVMnBmQCRGbZOAu6i6as=; b=pay5MHOimrFJCOr2bMhTf2Cpmyz3WnlvaiRJOwXjQChx6RAey9aVgkJ6pAqCsGJFcF DlC540+dhwovm84og9pREjkmRIBWvmysGE014Ri3LCLujoA2bcFjGjdv2qzDPIN9uh5E IL9Zz8KDkEYzJOuOclylw/d3St7UW0g6Av4fVwT8XO454++JofZLVgWvNiFazWP9yBnN VdUJGQweRky7zHdgBHRa1mKRdQwgq+teoB3pBem0nFP2lTzMlr0yIEQP3ZhCwtE6Y3iB oJ7xrYb30WHo4lKF8FFY+rXz7ac9J1i/2BiWalnIkPsEUZiRVF1IbVN16d+2sjjHvq+V De2w== 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=QNCUWJS54liesdignQo1OlFCVMnBmQCRGbZOAu6i6as=; b=cQlAg8nkyNo8Lo4lOanx2JY4Nb0vI/dEvZYP8b2d2J8raevPRJmIbWm1XEV91P4ShH /0K6O1p9vLz55aNJfD3FJylOueAuSD7kMYHpixEbRgb80JyumEznsw+/2QPyViMy6H2s xwQQpkyaSlTCjxge2Cj5p0zOCNrY76sBQmWYn/aVUB/EeoWVENpBeiG8h9FHwegCs7X2 DKDbXiSp32Tv78WH7hDUgh0duDZ1qVTrD20LTDuHU0TOd+rd9LbpvHdLsfQUfiv4qBVE CdqMKfrthiRM/EVY09BiMe0Fw+2LU+dGh6Wb7qBHVU32yxd84Q5exrUChj3hoVGx2DG9 OIzQ== X-Gm-Message-State: AOAM533nIUyq/WAMSpJUns1aM/NCbK6GIbHIqfGGY5n0fOehPdMED7eE r3pPbl7z+HAQfFDazDaP9qmhtvOegBiVdWdO0/s= X-Google-Smtp-Source: ABdhPJwvq04VRKLMc7ClRPL0TAqnrlKcHzmRVVY+JR2z/FWPDwYuxIZsQFxUomjPoXNDXFWOLpp9NImgfUQj0usDuOo= X-Received: by 2002:a05:6638:e93:: with SMTP id p19mr67014050jas.67.1594505865151; Sat, 11 Jul 2020 15:17:45 -0700 (PDT) MIME-Version: 1.0 References: <1e39fdcb-16d2-42c3-95cf-507f7b647b50@www.fastmail.com> <3bfb89c5-c8fd-4587-8c1f-8b7bbbaca692@www.fastmail.com> In-Reply-To: Date: Sun, 12 Jul 2020 01:17:33 +0300 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000af471305aa31d3e3" Subject: Re: [PHP-DEV] Possible RFC: UniqueInterface that throws exception at refcount > 1 From: maxsem.wiki@gmail.com (Max Semenik) --000000000000af471305aa31d3e3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Jul 12, 2020 at 12:47 AM Olle H=C3=A4rstedt wrote: > You're misunderstanding. :) Yes, it should be shared, but not with the > same access level as the owner. If a dependent class closes the > connection it will cause spooky-action-at-a-distance somewhere else in > the program. Sorry, it's related to refcount as ownership checking and > not to throwing exception at refcount > 1. If your class doesn't know whether it created its connection or it was passed to it, it's badly designed. Not only would that mix concerns (making DB requests and managing connections), it would also be hard to test and hard to keep in the programmer's head. Use dependency injection to avoid that. I'm not convinced by this example. You can't use ownership as a protection against code doing something stupid. Imagine for a second you've prevented non-owners from closing your connection. Will that also prevent non-owners from dropping your database? What about them messing with your connection object's properties? Language features can only prevent developers from making accidental mistakes. Bad code is not an accidental mistake. --=20 Best regards, Max Semenik --000000000000af471305aa31d3e3--