Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104544 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23211 invoked from network); 2 Mar 2019 12:58:05 -0000 Received: from unknown (HELO mail-wr1-f44.google.com) (209.85.221.44) by pb1.pair.com with SMTP; 2 Mar 2019 12:58:05 -0000 Received: by mail-wr1-f44.google.com with SMTP id w2so347830wrt.11 for ; Sat, 02 Mar 2019 01:45:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:cc:from:message-id; bh=9VWhFba5RgNsu6qc+nSXf1mbtYUxbG+OWmZ2fzdB+pI=; b=q81jpgBXyjK0FzZ/96AE5r1RgHJoSoaLPrHqmrpG6j2LQqAXg1qIO+nOQ3Tjl8Wdef EdInR549h5Wr3LTc2b9rV9gRzGbV+AxAlyClwQszmxscsbxT/AGmHosoOVLPg6tx/frK aSfjEMkBdJArrUMTb3iQvZGLFP+y4eYOp1sBQPm//d1VphD7dB7UpLTaOs/q37q8Er2y EQVPg5MM5dmb+ccw+5u+BXfaSUIXutLi7oQMczjiOLqxahFLY4Gugp1ULHiHBCu0YJEy jWvh1MM26DNnh7NfyPFWvHTtbxrQw2m6loqcTol36NxgFGrZ/zolC1fFru1eJtSSOfuI vsGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:cc:from :message-id; bh=9VWhFba5RgNsu6qc+nSXf1mbtYUxbG+OWmZ2fzdB+pI=; b=mnJ0WkBG3vS8mfCopQynQuWBQ0FuKV9i5n67k5ezBz0pthNRr7V/kEFfCRCCkbw5Tk V9XluGFJxhrbXvSJtodsAgLBNQESr3+oaWhLp4WNORE53nSQUbAcv3gML6h/J/YUmwNf j6DERE6tWRTY7CwuhdseU3xBZx+8fqLJ/qjS8PHrmAy/sUYvcwkl+Wyzz4PuSLkCLpgz x8MG1jZBz2R164tqP0UC5/iNpAr1nTHKURVw6bZFouKHH+vIUA0X85OZa988jPnQ7iUw MXXK/KRkz030ZwdwIfjGseqUocklNpC7adzR4PoXkCpnUkiTbSwjfUlGP4MeBsgSZSI+ Kgug== X-Gm-Message-State: APjAAAW2ZqwFMgiEaOcRDtWGbXT7X7qMagtVO3wTDpOXezV4eTazUArm fupID9raWi3hd+LgS3dIyw7M1k1k X-Google-Smtp-Source: APXvYqz6STJVrnwAaM+o1tsgKZKSU1cmeIuhvVhdEJvs2m8Xlew8KlzgGM1/MiZtRSRoa4jVrGgTPw== X-Received: by 2002:a5d:53cd:: with SMTP id a13mr6452990wrw.146.1551519926098; Sat, 02 Mar 2019 01:45:26 -0800 (PST) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id a184sm658160wmh.37.2019.03.02.01.45.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 02 Mar 2019 01:45:24 -0800 (PST) Date: Sat, 02 Mar 2019 09:45:22 +0000 User-Agent: K-9 Mail for Android In-Reply-To: References: <226B512C-02A7-4555-9288-D7A2DA89F068@benramsey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net,Christian Schneider ,Nikita Popov CC: PHP internals Message-ID: <49A08E7C-22CA-4165-AF33-61E19D4E360D@gmail.com> Subject: Re: [PHP-DEV] [RFC] Consistent type errors for internal functions From: rowan.collins@gmail.com (Rowan Collins) On 1 March 2019 12:02:29 GMT+00:00, Christian Schneider wrote: >I have an example where this might be harder than necessary: >I'm importing data from an external source=2E Now in the real-world the >import data files can once in a blue moon contain bogus data, e=2Eg=2E >there could be an array instead of a string in one single entry and I'm >doing a strlen() on it=2E > >Previously this triggered a Warning but the import job completed for >all the other entries while still informing me that something was >amiss=2E The problem with Warnings is that processing doesn't just continue for all= the *other* entries, it continues with *this entry that turned out to be b= ogus*=2E So now rather than a missing record, you have a record containing = a 0, or the word "array", etc; and the Warning probably won't tell you whic= h record it was that failed=2E >The new way leaves me with three options:=20 >1) My import jobs stops at the single broken entry >2) I can add type-checks for every single field >3) I can start wrapping code with try/catch Option 2 can be stated differently as "add validation for each input recor= d": this isn't the same kind of type check as a library function picking up= coding mistakes, it's handling of untrusted input=2E Option 3 can be thought of as the transactional approach: if an error happ= ens within a logical record, you can log that record to a reject file and c= ontinue with the next record=2E There is definitely more effort to doing one of these compared to not doin= g it, but both seem preferable to letting bad data through, whether the lan= guage forces you to do something or not=2E Regards, --=20 Rowan Collins [IMSoP]