Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105141 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83634 invoked from network); 8 Apr 2019 12:39:09 -0000 Received: from unknown (HELO mail-it1-f179.google.com) (209.85.166.179) by pb1.pair.com with SMTP; 8 Apr 2019 12:39:09 -0000 Received: by mail-it1-f179.google.com with SMTP id y204so19606086itf.3 for ; Mon, 08 Apr 2019 02:35:45 -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=q8o2A/ynS85jxtcFMD46hmRS3yqN8pJk7Tb0KPQTyPg=; b=jX5iG88VQW3MOAqgc9h6etIx4D5JCQxgIpicEWf1TGQrikYz9U/RKLTbCrYuRqEqOo PMzThY/VzH2/Zq59ChYjX7FCDWKsdXdHbboXR2yLh3wqTQjqmt3mLgryKkW6VzlU7bSs yNnkPMSwuelnCfEGvjXqwRN36zcXiAR2LIWLit5EuEFmC7I3PvzjROw5aGKmsfjr6NPY gUXNtaYSagi42MLsAIyndmiMD1p9Dt/DLE4oPJorLd78MO4OP9MGCRMIH6n2EMl+nAWb duVm6sJubNsz4s6PevVt/1W/pZGZJU4KVAEtlmcmMNfEiB67gBu7vbo6vBVEoRG47H2m ZW6w== 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=q8o2A/ynS85jxtcFMD46hmRS3yqN8pJk7Tb0KPQTyPg=; b=LhoaIB/NETc6+GMcJssPbX82sGA8jaXrFaAX4Y6FV3LgmZomVnB/l9k6oKEjyfeIu+ FC3dWwlNGugHODp9eBm831sHmfu8XQAa8FI6g1suw1ReIARTrn8pansv7BgdksZ+ZeFH QOKHJUie3hQsFzzH8qhFzMTZhL+Pm6gHGxhAW7W349pexrS1cRdQQ4GUX0i95DUGGEHq aeXlAnqV2ay5r6xrpS4e6RSUopMXADCg1rFfhmEHhGEo1rN/Djj9jKeVdW56cNyVtzdr 2dfm55gcMP6oWEW9t6iYe7DUBKSbcIRrV7hg8tOXJjz93atcDBuR4v02Mlds4Gd881Cg MQRw== X-Gm-Message-State: APjAAAVy3w/QIRK/jYxxl1zmZAPdriZ0olgI0a8yuuC5SwWn1xvWhM7o kLdDSN9EmQkfS7cb+h3ktwhtE4vIW/4js+GHCnNWBM1c X-Google-Smtp-Source: APXvYqzOyTjy4IZfGbV7SbGwobRXb+c0FlVIPbI/8OizI7PI03KnKKbR2xETbn65KHvyQvt3j5U4W0Dee60YDrOpyi0= X-Received: by 2002:a24:e04f:: with SMTP id c76mr19818713ith.113.1554716145111; Mon, 08 Apr 2019 02:35:45 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 8 Apr 2019 11:35:31 +0200 Message-ID: To: Dan Ackroyd Cc: Guilliam Xavier , PHP internals , David Rodrigues Content-Type: multipart/alternative; boundary="0000000000008e57c90586018fba" Subject: Re: [PHP-DEV] [RFC] Nullable Casting From: benjamin.morel@gmail.com (Benjamin Morel) --0000000000008e57c90586018fba Content-Type: text/plain; charset="UTF-8" > register_cast_function('?int', 'castToIntOrNull'); I would quite oppose such a generic implementation, as it might have unexpected consequences in other parts of the codebase : it's a global configuration set at runtime. I quite like the idea of nullable casting though, as I've come across a few cases myself where this would have been useful and would have made the code more concise/readable. Ben On Mon, 8 Apr 2019 at 04:55, Dan Ackroyd wrote: > On Sat, 6 Apr 2019 at 08:53, Guilliam Xavier > wrote: > > > > Hello internals, > > > > David and I would like to open the discussion on our joint RFC: > > > > https://wiki.php.net/rfc/nullable-casting > > > > Mainly, it would enable to use e.g. `(?int)$x` besides `(int)$x`. > > > > I'm guessing you don't actually have ths function getIntOrNull() in > your code-base? To help me understand where this would be useful, > could you provide some 'real-world' code where this would be useful? > > By the way, this RFC is a special case of something that could be far > more generic. If it was possible to register callbacks to be used when > casting, people could do something like this: > > function castToIntOrNull($value) > { > if ($value === null) { > return null; > } > > return (int)$int; > } > > register_cast_function('?int', 'castToIntOrNull'); > > $x = (?int)getIntOrNull(); > > > > Additionally, it was requested on the mailing list to consider adding > > support of nullable types to the settype() function, > > e.g. settype($variable, "?int") > > Someone probably needs to make an argument for it to be in core, > rather than just saying that it's something that could be done. > > cheers > Dan > Ack > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --0000000000008e57c90586018fba--