Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121580 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71608 invoked from network); 4 Nov 2023 10:46:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Nov 2023 10:46:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5DF7A1804B4 for ; Sat, 4 Nov 2023 03:46:40 -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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 4 Nov 2023 03:46:39 -0700 (PDT) Received: by mail-vs1-f54.google.com with SMTP id ada2fe7eead31-45db31f9156so220790137.1 for ; Sat, 04 Nov 2023 03:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=youmind.jp; s=google; t=1699094799; x=1699699599; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BfZXdgMst9f9nVw0XBFREKGJxMkAmSgKvhsMRZz8g+o=; b=MPcPQWfPBQ+rl8TOIRadENH80AWb/sKx7uDwCDUwzzit8GGWJrS2C9WC00xN21XGrt JJ5OjymO8iazOT9R1tCNdG+45zPInH0hV0vvFS8tS0uQ71l4q/B72QkJtzRpwxslHARk pIV9zin0nsOLsjV3Ikk+flw+qDsS6z+UMf4Ed1yDIoT5+/WUxCAKpCBUQT7r40vH1x/K Q5OOv+QY2C9zgYqq7JdPkcw5MQMRzcokZUfTfGhjvKgwYAnDc53mgtT7VlIh8dGWSwnY 4QKAtoF9ZeSNC6gMm1eMAU52eJX3uLEdO9Met5ib0eqTuiRXonc4BRLC8B4p3DdUaDlb R98A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699094799; x=1699699599; h=content-transfer-encoding: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=BfZXdgMst9f9nVw0XBFREKGJxMkAmSgKvhsMRZz8g+o=; b=d7XT2bw/kDehZYni8G27luYbjw+lXxGcZuZrSTN8Cug27FUIxm+ri1suLBaubT4YcL zpIqDXzjW01P33FEnLJTrKM74uTP30D5AMAM9pMf4sZNSGVBTugIo+FqtlK8FXEf+iSV Wm9zOl8uRXgzjI/5NVFpTz3+nQjp2FMKZlI0PhzGOqz8q+kNbLd8NPffjECLdKK89haE S3dEpCvUJT96o4hlfpA51G4f/m/K6qfN/IlK3H0alvBY4+QCj+WLgjmpuwaxTxjcZqu6 ZZuvgb0OhjP1+5SoKwmjKrl52h3qyHJOLGlHPc/drLsK0dBcgsuT1yGhHI3i4h5KpTAG TOEQ== X-Gm-Message-State: AOJu0Yxz8m/dmahjCNBBvAUE9KcjpAeyrHkTJVCU5+/A0vMfU5F0tqGM U+9WYURBVmHoaMvEFoPAn+4cWKPws6AQ1occapb6bQ== X-Google-Smtp-Source: AGHT+IHqTydB9/3o5BfTJUUh890EILIxawLhrpoTDfHH8jmyPpzc0xv7rA7yhQpW8sz53UuwMu4PmJlikrU22LwIP4I= X-Received: by 2002:a67:e1c8:0:b0:45d:9988:2354 with SMTP id p8-20020a67e1c8000000b0045d99882354mr167929vsl.28.1699094798925; Sat, 04 Nov 2023 03:46:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Kentaro Takeda Date: Sat, 4 Nov 2023 19:46:28 +0900 Message-ID: To: Saki Takamachi Cc: Ayesh Karunaratne , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Fix the inconsistent behavior of PDO::PARAM_XXX From: internals@lists.php.net ("Kentaro Takeda via internals") Hi, internals. > As shown in the following issue, the behavior of `PDO::PARAM_XXXX` is > inconsistent and I would like to fix this. > https://github.com/php/php-src/issues/12603 I consider the current behavior a bug. And some of them contain behaviors that are very confusing to users. > It may be an xkcd/1172 case, but these kinds of cases are very hard > to spot from static analyzers, and are often only surfaced > in production only if someone spent enough time to dig deep. As previously discussed by Ayesh, assessing the users' impact of a fix for this issue might be a little challenging, but I think it's important to address it to prevent confusion. Taking PostgreSQL as an example, let's consider the following PHP code: ```php $pdo =3D new PDO('pgsql:'); $pdo->exec('create temp table t(boolean_column bool, text_column text)'); $stmt =3D $pdo->prepare('insert into t values (:v1, :v2)'); $stmt->bindValue(':v1', false, PDO::PARAM_BOOL); $stmt->bindValue(':v2', false, PDO::PARAM_BOOL); $stmt->execute(); $result =3D $pdo->query('select * from t'); var_export($result->fetchAll(PDO::FETCH_ASSOC)); ```` The result should look like this: ```` array ( 0 =3D> array ( 'boolean_column' =3D> false, 'text_column' =3D> 'f', // HERE!!! ), ) ```` Even if we insert `false`, it will change to `'f'` when we select it. This is fundamentally a user mistake. However, the big problem in this case= is that the value `'f'` after the change is *truthy*. Who could have predicted that even though you entered `false`, it ended up being `true` ? I've seen a lot of pointless code to deal with problems like this where types are not uniformly formatted. As Saki says, we need to think carefully about whether we can accurately treat this as `bool`. However, regarding the above problem: * Fix *truthy* / *falsy* such as `int(1)` / `int(0)` to a form that can be correctly determined. * Make this behavior consistent across as many drivers as possible. Even this small fix would eliminate much of the confusion that is currently occurring. (Of course, it should ultimately be treated as `bool`.) I look forward to a resolution that will be satisfactory to all. Thank you for your attention. 2023=E5=B9=B411=E6=9C=884=E6=97=A5(=E5=9C=9F) 17:56 Saki Takamachi : > > Hi, Ayesh, > > I forgot to tell you one important thing. > > Binding of parameters is not actually done in the `bindXXXX`method, but i= n the `execute()` method. Therefore, when preparing a new method, a slightl= y larger mechanism is required to determine which method the parameter was = set through. > > Regards. > > Saki > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >