Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127200 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 74A1C1A00BC for ; Sun, 27 Apr 2025 16:05:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1745769796; bh=UEw1rgqK5guE8ZKKVyU60gGsZcUHAUfena6KYNsvNa0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NV5CMddAIVO0RvSm+YBGHWik+iYmOUP8CPC3Uhp376K4wfLHuhUG2nBpI+ikJSMlJ whuhsQWg4VsIyVQRZwxutmY8Hbbrax/UfRC5PTQEqB2y7yVWsWpGcIIkCVhSW8+cES 70FgDmBdu2ZxxyqGOEDhA812kiahz6TF+WArVeIGaO5IbDsyPxYse/gTAy+IClAnIM 9XNPnEa+/j+nHY9spj6WDP6jPEr3UvP/wgVmk5aKQssmcHnNHAiARpSbQklRHE6/xP 5LNmbZ+ptpBzGdEiUTKMrX7YsAQiaCYVebDsk3S+ioObvoB6k8X8pBUVK25w29cdXM 06JDIJpGOBkfg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC68118006A for ; Sun, 27 Apr 2025 16:03:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 27 Apr 2025 16:03:15 +0000 (UTC) Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-6ef60e500d7so36612297b3.0 for ; Sun, 27 Apr 2025 09:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745769932; x=1746374732; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BWZg+icg4ODPj1KukYKHxNMc2XSuR7aQon5LFaPdUn0=; b=GPqjudAQBZch60jj1qVsi2yOs782wg9/dMY/1q/U5NrTMRWsvoh8Du0V3WJz7NaxyY tXRPpdahv7Wre/ygjlJ2yrp02EAK/H4imOLkJLYev0Iojw3LPiAO2YQGW/mf/sHvUfCW BQyA0WO9mN6d++trZPV4HHkqM1NXweeT23AJhvoKy1ijTsRUVEtG2dd1UEjKG+ol9tA7 GxgWpKcnkdxUXBMI0ypqyGJm3FP/qKqd+9eCjeSA7vQimLNlu7Jl9uHFSGkqo3cmS6aR WXVtxt2dumH68GeNDt8CvuCf5jlZUmjXO9+adT7twuY8yrR/wv+NoD1iS2naxx67kXMU 1GHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745769932; x=1746374732; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BWZg+icg4ODPj1KukYKHxNMc2XSuR7aQon5LFaPdUn0=; b=iADZGU8k9RB6j+j+m71R1w5SGom1sbN4vmbyDtgKuJJVCEDifSMlsITpr7DvDvwPb8 B+HpIIrP26c4XUHw7d6WVjt3M+hV4Rb+hQkZgNLDsj4wHiyZJlVPOeJsex9bqHeCJ2fw WrEEPbZIYevs1xchz0qgFBEyUOIkg21p0PyABBsSGhNfj39kj0RF1ZL2JXlW99xGpW0g nkfQ5QDp4yPZGRHMuCg5XExdHQS+rEKL7P/jcep8WQqkO/45B4xarOY1Zdlkuqsyu93Q tQjouCpD85SFgfPAd7bK/Pkob6Fo+rZx1qN4DmquS4YNYnH5GC7YgdbFFjMs9X5IjBpK z8og== X-Forwarded-Encrypted: i=1; AJvYcCUlZufXuPwsqyLwIZzRxd+GuAKTQR1Jm9bfvJPd4fCroOSbLI1oq51fAznlXfmnjxPBDY2d0jnRtIs=@lists.php.net X-Gm-Message-State: AOJu0Yy1yMk4hMYIlDy2A2NTjgbwhCcWqlfLGMhXsllDcoMlU/d9xCt1 a0hl2KRwWPzc+h0Hipiogd9salnuyBr1Ygyvy1e/jMr5icQ6YLJKhFKCVhAQYAOeUhs4QZLCcTu F9siHQVpnrMSVII3ss0De9Ge4Tw4knoMh X-Gm-Gg: ASbGncsi3XW9rH20NCkOLl8/ONgudU8dpBRO9qaY+Q0z/jrSHgflqB19E0hdTL/dRlH Gn+mmlMgKdJ67Uzk0HDr+8xCVQtevr0JTZb49X/7qpaxYi4TntE+ZQKS7lEC4GxRrQ59YIxeZBm DivFAWTcIkD9Z0Ue4HBrShd2RI89QKxlYV X-Google-Smtp-Source: AGHT+IFpuujBMCG3o37SCOTtBAMDyM7LtWgludMcolO004UZlSvDC2UJ7oI8btz9w6WKemCcDg7ZSMCf1HCmsWLBR9E= X-Received: by 2002:a05:690c:4446:b0:6fd:4473:5184 with SMTP id 00721157ae682-708541ec3afmr128765397b3.35.1745769932399; Sun, 27 Apr 2025 09:05:32 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <39597a9c-6854-40c6-a529-32b2b178cb27@app.fastmail.com> <64f44c6f-a1ef-4a26-9063-d4d90fdf678c@app.fastmail.com> In-Reply-To: <64f44c6f-a1ef-4a26-9063-d4d90fdf678c@app.fastmail.com> Date: Sun, 27 Apr 2025 19:05:21 +0300 X-Gm-Features: ATxdqUEw7kJ1wZswcyQ5yO0cWlWviSR2-n7eakDxzBoqDo2rS7jm3UOECBdiRXA Message-ID: Subject: Re: [PHP-DEV] Concept: Lightweight error channels To: Rob Landers Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="000000000000ae2d210633c4bc05" From: edmond.ht@gmail.com (Edmond Dantes) --000000000000ae2d210633c4bc05 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, Rob. > I was quite surprised at how *impossible* it is. ```c static zend_object *zend_default_exception_new(zend_class_entry *class_type) /* {{{ */ { .... if (EG(current_execute_data)) { zend_fetch_debug_backtrace( ``` It's not that this is 100% impossible. PHP is a language with an execution context, which means PHP can hypothetically change behavior depending on the context. This means it's entirely possible to imagine code like: ```php if (EG(without_trace)) {} ``` One could follow Python's approach and create the backtrace only when the exception is thrown. But this isn't a particularly elegant solution. Besides, in 90% of cases, an exception is created to be thrown. Use a deferred Backtrace generation algorithm? Such an algorithm is almost impossible, because the backtrace is built based on the execution context, which will be changed once the function returns control. There are only two realistic options: - Either don't use a backtrace at all, or use a minimal version (only FILE + LINE). - Generate the backtrace only when the programmer explicitly requests it, but then accept that some information will be missing. For example: - raise $exception =E2=80=94 does not generate a backtrace. - throw $exception =E2=80=94 generates a backtrace, but only from the poin= t where the exception is thrown. A lightweight backtrace might be imperfect in accurately indicating the call path if multiple functions are on the same line, but otherwise it saves a lot of memory and CPU. The raise/throw option might also make sense. But it has more nuances and contradictions. --000000000000ae2d210633c4bc05 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, Rob.

>=C2=A0 I was= quite surprised at how=C2=A0impossible=C2=A0it is.=C2=A0
=
```c
static zend_object *zend_default_exception_ne= w(zend_class_entry *class_type) /* {{{ */
{
....
if (EG(cur= rent_execute_data)) {
=C2=A0 =C2=A0 =C2=A0zend_fetch_debug_backtrace(
```

It's not that this is 100% imp= ossible. PHP is a language with an execution context, which means PHP can h= ypothetically change behavior depending on the context. This means it's= entirely possible to imagine code like:=C2=A0=C2=A0
```php
=
if (EG(without_trace)) {}
```

O= ne could follow Python's approach and create the backtrace only when th= e exception is thrown. But this isn't a particularly elegant solution. = Besides, in 90% of cases, an exception is created to be thrown.=C2=A0=C2=A0=

Use a deferred Backtrace generation algorithm? Su= ch an algorithm is almost impossible, because the backtrace is built based = on the execution context, which will be changed once the function returns c= ontrol.

There are only two realistic options:

  • Either don't use a backtrace at all, or= use a minimal version (only FILE + LINE).

  • Generate the backtrace only when the programmer explici= tly requests it, but then accept that some information will be missing.

For example:

  • raise $exception =E2=80=94 does not genera= te a backtrace.

  • throw $exception =E2=80=94 generates a bac= ktrace, but only from the point where the exception is thrown.

A lightweight backtrace might be imperfect in accur= ately indicating the call path if multiple functions are on the same line, = but otherwise it saves a lot of memory and CPU.

The = raise/throw option might also make sense. But it has more nuances and contr= adictions.

--000000000000ae2d210633c4bc05--