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

Extended Object Normalization #497

Closed

Conversation

ragboyjr
Copy link

  • Added better support for serializing common
    types of classes since a lot of classes use
    private fields which make the default object
    normalization basically useless

Signed-off-by: RJ Garcia [email protected]

Description of the change

Description here

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers mentioned in a comment
  • Changes have been reviewed by at least one other engineer
  • Issue from task tracker has a link to this pull request

- Added better support for serializing common
  types of classes since a lot of classes use
  private fields which make the default object
  normalization basically useless

Signed-off-by: RJ Garcia <[email protected]>
@ragboyjr ragboyjr force-pushed the extended-object-normalization branch from 331bd30 to 0e6ce04 Compare August 19, 2020 02:17
@bishopb bishopb self-assigned this Dec 2, 2020
@bishopb bishopb added Rank: 3 - Minor Tackle when there are no actionable Critical or Major requests. Status: 1 - Discussion Stakeholders are discussing the scope and characteristics of the request. Type: Enhancement Changes that add to, improve upon, enhance, or extend the existing component. labels Dec 2, 2020
Copy link
Contributor

@bishopb bishopb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these improvements! They seem like a good value add. There are a few changes necessary, but otherwise we should be good to go.


try {
if (method_exists($obj, 'toString')) {
$serialized['value'] = $obj->toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method toString we would think would return a string, however that's not guaranteed: someone could do function toString(): resource { return fopen($this->path, 'r'); }. Recommend that the output of $obj->toString() pass through serializeForRollbar to ensure it's serialized. That may require some juggling of the checks.

$serialized['value'] = $obj->toString();
} elseif (method_exists($obj, '__toString')) {
$serialized['value'] = (string) $obj;
} elseif (method_exists($obj, 'toArray')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies here as it did with the toString comment: there's no guarantee that toArray actually returns an array.

}
} catch (\Throwable $e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwable is not safe for 5.x, which this version of the Rollbar library supports. We also need a Exception block to handle that version.

@@ -0,0 +1,11 @@
<?php

namespace Rollbar\TestHelpers\ObjectSerialization;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: these may not pass linting, as we have namespace beside the <?php in other files. However, we will be changing this in the next major iteration of this library in order to support strict_types.

@bishopb bishopb added Status: 2 - Accepted The scope and characteristics of the request are defined and ready to be worked. and removed Status: 1 - Discussion Stakeholders are discussing the scope and characteristics of the request. labels Dec 2, 2020
@bishopb bishopb removed their assignment Feb 13, 2022
@danielmorell
Copy link
Collaborator

I am closing this PR as it has become stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rank: 3 - Minor Tackle when there are no actionable Critical or Major requests. Status: 2 - Accepted The scope and characteristics of the request are defined and ready to be worked. Type: Enhancement Changes that add to, improve upon, enhance, or extend the existing component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants