Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103719 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 59983 invoked from network); 12 Jan 2019 23:38:40 -0000 Received: from unknown (HELO mail-pl1-f180.google.com) (209.85.214.180) by pb1.pair.com with SMTP; 12 Jan 2019 23:38:40 -0000 Received: by mail-pl1-f180.google.com with SMTP id b5so8314445plr.4 for ; Sat, 12 Jan 2019 12:13:52 -0800 (PST) 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=ZTsfn8N5GzDzhWO2lD5tpXABXzckJ4ALacB7/4Ilzj8=; b=QfuE9LA1KVUULtJ/JJwR4U0y/QhvGow059cJjQi66UtDP5EvhARUTaI7HqaQHuwTWj cMtOGwLu+2X/RxlO3giQ5Y1DhqaE/cIESfmTIRwN1ajM9QeHRLBdDiLs21XPTBE1bkod izJfRbmceNmJ+MnzYurvrhc+0w9yKUtqf2Neh1P/Coy1AR9kHOK2xu72VLGN5cYHLglj 3kfQNq3xhMjATXSZeMSfu9hHHYtvT0Dv32Jsjcj+lVJLqsP5RaJdyzTbg1PpndOJwOY4 sNrmTk1e+veiEtoi+zyQaX0SiURKJ9mOfb3GyObT/plB6724zHdEkm+z/sMKDXtGE2hs 18/w== 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=ZTsfn8N5GzDzhWO2lD5tpXABXzckJ4ALacB7/4Ilzj8=; b=l5pWb8HpfNzUMykLfrjzYlCUxeb9uE+uDGxYZxkG3GZjEN/mmIFT4P8jXWuK4Xgo+p X31g859N55R4Fb/j6dmskC2rQd/9LVS08YrEJdeK+uzUJHyO9CAKTyyX9JlfdXUguE3N Rc+lBTnoLSwKNin/bMNR3S+OUTp9cupZXByvBSJge6vQ0+JQ9Cpw+QzguGrtVzSCJqvm nSIzCm3rF4IQTYfoU1F1mvETtP6ICHUpka7e9lG5LcedLZdDpyHqjtCbQvEZo/lBgwBM xljo+iZEoKmUozSKoOKRZ3NhOcAgpyYu6HAosG3UXGk8g7q0/bJvddvsSwNaL1oTq+xu MPPg== X-Gm-Message-State: AJcUukc+hbWpxfTHxE2afVL+OECv4jmjUd81/vU7ZJokrTyBTh746A4B 4UiQMlB9oH/t1coyG67gOtRvuZWM2G8mwCjNW0ObEfuCHM0pZg== X-Google-Smtp-Source: ALg8bN7eC4J8Je1mT6DYSn1+R2Cx0SBaZ8EoO9wrWTwOjv8wSJDtzHR5cDo8fqUK5tW1YjwS9GworePXOyGsgr6FEM4= X-Received: by 2002:a17:902:1126:: with SMTP id d35mr18490680pla.1.1547324032120; Sat, 12 Jan 2019 12:13:52 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 12 Jan 2019 20:13:41 +0000 Message-ID: To: Craig Duncan Cc: Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Making stdClass iterable From: Danack@basereality.com (Dan Ackroyd) Hi Duncan, I quite strongly dislike the idea, as it sounds like this solution is a hack for a particular use case, and that use case doesn't seem to be particularly important to me. I say it's not particularly important to me, as you could solve it right now by: i) asking json_decode to return an array rather than an object. ii) converting the result from json_decode into an object that implements traversable. iii) By accepted that PHP's type system isn't powerful enough to make all programs trivially type-safe, and so to not use the iterable parameter type here. This won't make your program any more or less correct, it will just be slightly more annoying to debug. Those seem to be better than special casing StdClass. I say it's a hack as you're forcing the language to fit a particular need with the available tools now, rather than thinking through what best end-goal would be. I think the correct long-term solution for this would be for us to revisit the union type RFC (https://wiki.php.net/rfc/union_types) and so be able to define a type like: type foreachable = object|iterable; The union types RFC would support the problem you're trying to solve, as well as other use cases without introducing special cases. cheers Dan Ack On Sat, 12 Jan 2019 at 19:39, Craig Duncan wrote: > > Hi everybody > > I'd like to propose a change to stdClass so that it can satisfy the > iterable parameter/return type. > > Firstly I acknowledge that this isn't an ideal solution, but I think it > gets us to a better state than we're in today. It shouldn't be necessary, > but while we have such a common function (json_decode) returning stdClass > we should make it easy/unsurprising to work with. > > https://wiki.php.net/rfc/iterable-stdclass > > Thanks, > Craig