-
-
Notifications
You must be signed in to change notification settings - Fork 17
Replace json_encode with Json::encode #621
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| use Hypervel\Support\Collection; | ||
| use Hypervel\Support\Enumerable; | ||
| use Hypervel\Support\HigherOrderCollectionProxy; | ||
| use Hypervel\Database\Eloquent\Casts\Json; | ||
| use JsonException; | ||
| use JsonSerializable; | ||
| use Stringable; | ||
|
|
@@ -965,7 +966,7 @@ public function jsonSerialize(): array | |
| */ | ||
| public function toJson(int $options = 0): string | ||
| { | ||
| return json_encode($this->jsonSerialize(), $options | JSON_THROW_ON_ERROR); | ||
| return Json::encode($this->jsonSerialize(), $options | JSON_THROW_ON_ERROR); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Standalone collections cannot serialize EnumeratesValues::toJson() now calls Hypervel\Database\Eloquent\Casts\Json, although the collections package neither requires nor autoloads the database package. Calling toJson() in a standalone hypervel/collections installation therefore reaches an unavailable class and terminates with a class-not-found error. Agent Prompt
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Model encoders corrupt collections EnumeratesValues::toJson() now delegates to the Eloquent cast encoder, whose process-wide callback can return any mixed value instead of native JSON. When an application configures that supported callback for model attributes, every collection starts returning the callback's arbitrary output or throws a return-type error if it returns false. Agent Prompt
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If an application configures Eloquent’s JSON cast encoder and it returns |
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
hypervel/collectionsis installed withouthypervel/database, the newJsoncall cannot load its class: collections does not require the database package, and the database package owns that class. CallingtoJson(),toPrettyJson(), or casting a collection to a string now fails with a class-not-found error instead of producing JSON.