Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106119 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52546 invoked from network); 30 Jun 2019 01:02:50 -0000 Received: from unknown (HELO mail-io1-f42.google.com) (209.85.166.42) by pb1.pair.com with SMTP; 30 Jun 2019 01:02:50 -0000 Received: by mail-io1-f42.google.com with SMTP id r185so20254359iod.6 for ; Sat, 29 Jun 2019 15:20:05 -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=TyqBu9vIziXfHJ8qaMdLSJ4fMhHR8Nux3A9JPYF30ts=; b=j0wvUc7DJmU+kQ15xvVXsf6GOeyjOKLihtiOw41TFFSNZc/LuEdApeBICqWdYU1gJi ub1k9NU/bC6Mty9LUHLqF5db1jwTUJTp9XghvH9S910TplBvD7ycZ++0NrztoMjllh6J edtTGql58eBCwhZkMaVbCyplH00uJu5kIOkFEde/h6T9dEaocGoPDWT/AtcF8hfsGWzi /DYf532KVFsXpshkxukG/uWq2Bm6f/q85Sd5++Ml5tapm2tiXMSVxJ2h/e/8hkWzg8tp GMqwI2eorUNbveR8z6EUpDaqLM1OybEDdRkTfxz6HygLifOvFjgdBB6IDO3yJUC0vuzU 8SlQ== 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=TyqBu9vIziXfHJ8qaMdLSJ4fMhHR8Nux3A9JPYF30ts=; b=sJ+H/1bA0m5nO2Dp8we0tKyukH/I9KA7qCRnorg+bFGX2w20CNrK0T1H0i+68tLPdZ HTFcOA+w8VGjcou3eR5EUYeA8Xf2QG8//KIyBcqmY0LrIG+2Fr2Psd9hVhi8l7s20kao FV4jjBZXPRgbFQRDXpLV3rLs775wm3tus+c+zoKFHWZah4lY/5PQkCbSQ1oUxyh6AMg3 Ny1pHNfspI85wBtZmN2oCBAv7mFJQY2Hxmz5PDzH+m0L4n/8ORN55L20uPdTsNvFmMKp vOD25KJXsbpfiTFG8vKVeFsHeV7RF3u/ctE52le7vBzPWszqGG758oQE4oI7BZv4t51E hegQ== X-Gm-Message-State: APjAAAVpCra1tsn0wMT1E3acdAWWEsfHGpDzDoClR4Dqb/VYvDKeOjiD HvTgDzyz/Pt+Bx8GX5mvUuYf8JVbnRI6lBPvSlk= X-Google-Smtp-Source: APXvYqwKZt2hG2oY6mqz3cP/X/ccpreKXITc4c3QWp94Vv+NB2zARC3IsEvjSvvVeId4fI/L9yDfsd2/+bqPK8chTP4= X-Received: by 2002:a5d:948f:: with SMTP id v15mr9731851ioj.93.1561846805178; Sat, 29 Jun 2019 15:20:05 -0700 (PDT) MIME-Version: 1.0 References: <8f07c0dc-f9a5-8c76-1d48-0fac762bfc4f@gmail.com> <92dba455-17df-41dd-c523-bb0db3c12078@gmail.com> <003b01d52e49$4db89390$e929bab0$@jhdxr.com> <000001d52e8f$a1f92b40$e5eb81c0$@jhdxr.com> In-Reply-To: Date: Sun, 30 Jun 2019 00:19:53 +0200 Message-ID: To: Nikita Popov Cc: David Walker , CHU Zhaowei , PHP Internals , Stanislav Malyshev Content-Type: multipart/alternative; boundary="000000000000042c52058c7dcc52" Subject: Re: [PHP-DEV] Memory leak in eval()'d code From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000042c52058c7dcc52 Content-Type: text/plain; charset="UTF-8" > > What is the "non scaled case"? To repeat what I said earlier: Without eval > there is no and will not be a leak. > The bug is that eval() currently reuses an existing class instead of > creating a new one each time. Calling get_class(eval("return new class > {};")) should be returning a new string every time, while for OPs script it > currently does not. > tl;dr: > while (1) { > get_class(new class {}); // should always return the same > get_class(eval("return new class {};")); // should always return > different, currently may return same due to bug > } Ok thank you, anyway the good news is that I found a workaround for now (creating classes of a given type once then cloning). And if I understand correctly, once the issue you mention is resolved (and get_class() returns a distinct class every time), I should have another alternative: ``` $object = eval('return new class (...) {};'); $class = get_class($object); $anotherObjectOfSameClass = new $class(); ``` And I do understand that my use case is border line, and does not deserve too much attention. It's very useful to be able to perform instanceof on objects that dynamically implement an arbritary set of interfaces, though. Ben --000000000000042c52058c7dcc52--