Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105149 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64100 invoked from network); 8 Apr 2019 18:39:01 -0000 Received: from unknown (HELO mail-pl1-f195.google.com) (209.85.214.195) by pb1.pair.com with SMTP; 8 Apr 2019 18:39:01 -0000 Received: by mail-pl1-f195.google.com with SMTP id ck15so7550921plb.3 for ; Mon, 08 Apr 2019 08:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=H1SUz4VqTGflKijwZPFgMGAJbj0bJOJCcXEFJePHf/Y=; b=LF/DmyIrGj6qRp58O/HXfHD/7jXhKRkodrH9yv3STRnGuy+LEeYECqiNmHgi8137vW 0wQiTGZoMhrzPSPtWfDMWheXMliQKVBsj6lt5e7ErB40P6bfFQzuAPAn5LGG6AYFp7lI ID8YevulZ00jgcjXdh+vkxFwKzFj+EunFANqAZyMN8jAM6P96qle0jno7aWJRM917r6E fVIhCLPkuzJ3BF7+0tY6qk1BpnaloAViKLXXJ2K0glQLgyUD7ijImOgzW1Tn0utj/tLM ESgALi8fGFJLPq5I7pvOvoo9kknQKsWFWXdJBxj0wWM+RZghGBuAErYfO77hQrB5txgb 4tQw== 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=H1SUz4VqTGflKijwZPFgMGAJbj0bJOJCcXEFJePHf/Y=; b=ReD1Ve16ZvZinMhC8Qc1M5nCiBEH35Elm2yJxpgr2jTXC8iDxwdYdhxUXE4yPR9UP8 8s0z6fNryigqVuFcgEuUSOVl+sBdsxphu+tQJqZcGM+lh4bylk9F84h8pXfjrnppYs1y 8WLeP9REUtx7Vr91d7p8UYqKYurKgDhKMaT5St13nOYULSnWTRJ1HkYVzb8NOShQ1ZD7 Lz44DbI2U9fygDO24NPy7/XpRB+DAX31ilddUCXp+k5YoxqE5rLlXRbTBzCE4X1H0WDc KEmnDs5990ZyxrBTW4wufvOIOp0TSZbxXYG4Pr2YEQy95wV7uynIwRDBiyEWTzZMCxx0 YWRA== X-Gm-Message-State: APjAAAX9iqoTCovCc5BUeCKf3TT0/8YXZOprZKEUav4ypeTris9/B8n5 mqCjdfXxl4x8Q86dC3Vk4rh22B6k/pTBEX3mPIWlXg== X-Google-Smtp-Source: APXvYqyPYh0Wnn+kKDl19I8lO/61K+1HgXK425BfWdoWR9PkoXhntVhzH+VU312VRTjehA6GO/7JlpHMDoOsNUsAnn8= X-Received: by 2002:a17:902:b68e:: with SMTP id c14mr30115582pls.49.1554737740475; Mon, 08 Apr 2019 08:35:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 8 Apr 2019 16:35:27 +0100 Message-ID: To: David Rodrigues Cc: Guilliam Xavier , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Nullable Casting From: Danack@basereality.com (Dan Ackroyd) On Mon, 8 Apr 2019 at 06:05, David Rodrigues wrote: > > Question: why just not check if $itemsPerPage is set like: > ... > Answer: because in this example we could do that (although the new solution is much more practical). Well, I disagree on that. That code is perfectly fine to me, and having more operators to understand and remember is harder than having fewer operators to understand and remember. Also, I have a suspicion that the reason why you think this might be needed is that you're doing too much work outside `Input::get`. If you made a separate function that for `Input::getInt` that did all the work of casting the value to int when appropriate, you wouldn't have to repeat all the work in the functions that are calling `Input::get`. i.e. you're causing a lot of typing to be required to further process the result of a function, when you should be making new function that does more precisely what you want. > In another case, I have a static factory method that depends of an ?int to be created, and I can't just skip it with an if() if user input is empty. But please can you post the actual use-case you _need_ this for. Or possibly update the RFC with that example. Currently, imo, the RFC is just presenting an alternative syntax for something that is not 100% needed. I do kind of like the idea in the RFC, but I think it needs a better argument for it. cheers Dan Ack btw, the code you posted as: > $itemsPerPage = Input::get('itemsPerPage'); > > if ($itemsPerPage) { > $paginator->setItemsPerPage((int) $itemsPerPage); // OK > } isn't quite the same as what the RFC does, right? The code equivalent for the RFC would be this I think: $itemsPerPage = Input::get('itemsPerPage'); if ($itemsPerPage !== null) { $itemsPerPage = (int)$itemsPerPage; } $paginator->setItemsPerPage($itemsPerPage); which even avoids the magic/horribleness of having to understand what PHP thinks is empty.