Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] display \Stringable values of objects #234

Open
iGrog opened this issue Dec 4, 2023 · 6 comments
Open

[Feature] display \Stringable values of objects #234

iGrog opened this issue Dec 4, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@iGrog
Copy link

iGrog commented Dec 4, 2023

I have a complex object with pure __toString() method.
Or object implements Stringable interface

It would be nice, if Buggregator shows result of that __toString() somewhere (without need to expand object)

class ComplexObject implements \Stringable
{
    public function __construct(private int $a, private string $b, private \DateTimeImmutable $c) {}

    public function __toString(): string
    {
        return $this->a . ' / ' . $this->b . ' = ' . $this->c->format('Y-m-d');
    }
}

example:

        $obj = new ComplexObject(5, 'Hello World', new \DateTimeImmutable());
        dd($obj);

Expected view:

image

image

Actual view:
image

image

@iGrog iGrog changed the title [Feature] display \Strigable values of objects [Feature] display \Stringable values of objects Dec 4, 2023
@butschster butschster added the enhancement New feature or request label Dec 4, 2023
@butschster
Copy link
Member

All information is obtained using the dump and dd functions from the var-dumper tool. If these functions provide the necessary information, we will utilize it. Perhaps @roxblnfk could offer additional insights or context in the trap package on GitHub?

@roxblnfk
Copy link
Member

roxblnfk commented Dec 4, 2023

Need to investigate.

@Kreezag
Copy link
Member

Kreezag commented Jun 17, 2024

@roxblnfk are you able to share the investigation result?

@roxblnfk
Copy link
Member

Hi. Yes, of course.
After diving into varDumper, I can confidently say that we can send any metadata along with the main content. This can include the result of calling the __toString() and for example getSolution() methods in FriendlyException, and anything else.

However, there are still unresolved questions:

  1. What if the content from __toString is quite large?
  2. What if calling __toString is undesirable because this call might affect something (mutable behavior, additional resource consumption)?
  3. Is a separate option needed for this? If so, what should it be and what should its default value be?

@iGrog
Copy link
Author

iGrog commented Jun 26, 2024

Is it somehow possible to get these answers from attributes?
Like this:

#[Pure] // phpstorm uses this to display toString value in debugger. Only `Pure` functions are evaluated
#[Buggregator(show: true)] // naming is up to you :)
public function __toString(): string
{
    return $this->variable;
}

@roxblnfk
Copy link
Member

roxblnfk commented Jun 27, 2024

#[Pure] // phpstorm uses this to display toString value in debugger. Only Pure functions are evaluated

Something new for me. Thanks.
I think we can reuse this attribute for \Stringable variables.
@butschster need to think how it might be rendered and what context name or structure we will use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

4 participants