Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80695 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72925 invoked from network); 17 Jan 2015 14:02:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jan 2015 14:02:25 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.212.170 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:34626] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/02-01125-E6B6AB45 for ; Sat, 17 Jan 2015 09:02:23 -0500 Received: by mail-wi0-f170.google.com with SMTP id z2so9125750wiv.1 for ; Sat, 17 Jan 2015 06:02:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=eNP6QRTLtcMWrXdEn5as7F16w3FXilaz31hLMstk4FI=; b=WBlgcik02cW8E9PbPmsMNrMU+x61HbVdlPYa8gDKzVgQgUzFpiSgDWuKxDon7PYQvJ ghHRxlnN1YRoqpUbwqKmQNsGg/THeMwxrsY+xiugCoMiyt5tM2YevUnt8PCmbeb4v7Fe wNOUY9dBa19rQUKZUGc7UjHJwrXIs2nXKKLjIWHAhQNVF+Cu1f/pXXefAdMrwfjlcpyH zHtYU9sAxt309S9RGAEKD1m1g+olQMSzF+TvyJTg8o2DOEXkpkWM1QyILERRSb5J833g MrwNFD+qJiAzoWOgTmOM9sNWLz+ChO0wJB/O0v+YtGQ0UJjV4Jfp6AmBkhqgWekKZKyQ mYnw== X-Gm-Message-State: ALoCoQlq3F7fnRkIOD9MlA0dFJvjN4v3xeIq1V9XosSTorWRaFv6ycH7GSaz8t9PLmpN/z3px6Vh MIME-Version: 1.0 X-Received: by 10.194.109.9 with SMTP id ho9mr39969287wjb.29.1421503339158; Sat, 17 Jan 2015 06:02:19 -0800 (PST) Received: by 10.216.94.196 with HTTP; Sat, 17 Jan 2015 06:02:19 -0800 (PST) X-Originating-IP: [78.149.5.244] Date: Sat, 17 Jan 2015 14:02:19 +0000 Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Class constructor behaviour From: danack@basereality.com (Dan Ackroyd) Hi, I've been going through some bug reports, and have found there are several bad behaviours related to class constructors that ought to be corrected, but could only be done at a major version. The bad behaviours are: Constructors returning null --------------------------- Several classes in PHP return null when there is a problem in the parameters passed to their constructor e.g. This is pretty horrible and should be fixed by making sure that constructors either return an object or throw an exception. Additionally the exception policy for core (that was previously discussed here: http://marc.info/?t=119263748000001&r=1&w=2 ) should be updated so that any constructor returning NULL is considered a bug, no matter what the ini settings are. To be clear, procedural code should behave as before, with users expected to check for errors. This would be a BC break for people who are handling the constructor returning null currently, as they would need to wrap that code with an try/catch block. The list of classes that show this behaviour is: * finfo * PDO * Collator * IntlDateFormatter * MessageFormatter * NumberFormatter * ResourceBundle * IntlRuleBasedBreakIterator Constructors give warning, but are then in an unusable state ------------------------------------------------------------ Several constructors check the parameters that they are given.....and then just give a warning when they are not acceptable. e.g. getParameters()); //Fatal error: ReflectionFunctionAbstract::getParameters(): Internal error: Failed to retrieve the reflection object in.. ?> Again, this should be fixed by changing the constructors to throw an exception if the input parameters are not acceptable. Although technically this would be a BC break, I can't think of any sane situation where people would be depending on the current behaviour. The list of classes that I believe have this issue is: * UConverter * SplFixedArray * ReflectionFunction * ReflectionParameter * ReflectionMethod * ReflectionProperty * ReflectionExtension * ReflectionZendExtension * Phar * PharData * PharFileInfo Constructor gives error ----------------------- Some constructors check the parameters they are given, and then emit either a 'Catchable fatal error' error or other error e.g. Despite the word catchable, this is not actually an exception that is catchable, it is an error. It is only if the user has called set_error_handler, and in the error handler they throw an exception then the code, that the error would be catchable. The only other class that has a similar behaviour is PDORow which gives a 'Fatal error' which can't be intercepted, but can only be logged through a function registered through register_shutdown_function(). -------------- The list of classes that have these issues, is possibly not complete. The ones I've listed above was not done through an exhaustive search. So, questions: i) Can anyone see a big hurdle in fixing these behaviours, other than it being a BC break for people who are currently relying on these behaviours ? ii) Are there any other bad behaviours that people are aware of that ought to be fixed at a major version? These changes would need an RFC to be approved I presume. However doing the RFC would probably require making a patch that implements most, if not all, of these changes. As that would be a significant amount of work, I thought I'd get people's feedback before starting that. cheers Dan