Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96603 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78582 invoked from network); 24 Oct 2016 17:52:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Oct 2016 17:52:15 -0000 Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.218 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.218 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.218] ([81.169.146.218:30285] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/D0-07271-A4A4E085 for ; Mon, 24 Oct 2016 13:52:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1477331527; l=4946; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=Tv+CcgU+P+nl+spscm+vSu6vD5zSi3mb/kpNWcdDPfU=; b=X7EiMhUvw8TVcCTrty1gXdfVzXG4jy7Z1+uF8AY1aPNXwoRIfYHA1dy3JLF9wPO49wF nz095x7zOt3GwVTNVEvoIJXT2DNXpmWhTFrF02rS2rGKh/XOZZVjhjI6qbIFhB/Bl7iPO fGsDA1dAo/W+hQr5ROvcwVsYopOfHQkXQDk= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLGvomb4bl9EfHtOnM6 X-RZG-CLASS-ID: mo00 Received: from mail-wm0-f50.google.com ([74.125.82.50]) by smtp.strato.de (RZmta 39.6 AUTH) with ESMTPSA id x0b9bbs9OHq73cM (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp384r1 with 384 ECDH bits, eq. 7680 bits RSA)) (Client did not present a certificate) for ; Mon, 24 Oct 2016 19:52:07 +0200 (CEST) Received: by mail-wm0-f50.google.com with SMTP id f193so136514370wmg.0 for ; Mon, 24 Oct 2016 10:52:07 -0700 (PDT) X-Gm-Message-State: ABUngvd319dJG+TvkVCATHnBLz80sp/CfiALO+Vnk02h2Gv+7/gnxNPOUwPnCTFlE2CmnRvr6/VytMMyMFz+xA== X-Received: by 10.194.176.232 with SMTP id cl8mr9507808wjc.225.1477331527179; Mon, 24 Oct 2016 10:52:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.177.153 with HTTP; Mon, 24 Oct 2016 10:52:06 -0700 (PDT) In-Reply-To: <93e54a0c-5bda-f21f-2637-765a32a1aba3@fleshgrinder.com> References: <93e54a0c-5bda-f21f-2637-765a32a1aba3@fleshgrinder.com> Date: Mon, 24 Oct 2016 19:52:06 +0200 X-Gmail-Original-Message-ID: Message-ID: To: PHP Internals Cc: David Rodrigues Content-Type: multipart/alternative; boundary=089e013d1cc8e4acca053fa00c82 Subject: Re: [PHP-DEV] Debugging with zero cost in production From: me@kelunik.com (Niklas Keller) --089e013d1cc8e4acca053fa00c82 Content-Type: text/plain; charset=UTF-8 2016-10-24 19:12 GMT+02:00 Fleshgrinder : > On 10/24/2016 7:10 PM, David Rodrigues wrote: > > Hello, folks. > > > > I'm thinking about a debug function to allow us to create "zero cost > > declarations" in production code, as assert() does. > > > > From what I understand, if I have something like assert(method()), > > method() will not be called in production, only in development. > > > > This behaviour is great because we can help the PHPUnit, for instance, > > to capture messages in specific places to check if some process have > > generated the correct value without test it alone. > > > > For instance: > > > > // On test()'ed method: > > debug(TestStack::put($varValue)); > > > > // On test method: > > test(); > > static::assertSame(123, TestStack::pop()); > > > > How it should be a debug code, should be important that it not be > > generated and executed in production. > > > > Could I use assert() to do that, in all case? Then I could consider it > > as "already implemented". > > > > Bye! > > > > You can already use assert in exactly this manner. > > -- > Richard "Fleshgrinder" Fussenegger > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > You can use assert as long as you return a value that evaluates to true. We use it in Aerys to have zero-cost debugging output: https://github.com/amphp/aerys/blob/6335cc224e54999185119a28684804e91be458ae/lib/Server.php#L169 However, I think it would be nice to have a separate statement / function that doesn't have that requirement. Then we could just use `debug($this->logger->debug(...))` instead of `assert($this->logDebug(...))` or `assert($this->logger->debug(...) || true);`. Regards, Niklas --089e013d1cc8e4acca053fa00c82--