this post was submitted on 09 Dec 2023
4 points (70.0% liked)

PHP

543 readers
1 users here now

Welcome to /c/php! This is a community for PHP developers and enthusiasts to share and discuss anything related to PHP. From the latest updates and tutorials, to your burning questions and amazing personal projects, we welcome all contributions.

Let's foster an environment of respect, learning, and mutual growth. Whether you're an experienced PHP developer, a beginner, or just interested in learning more about PHP, we're glad to have you here!

Let's code, learn, and grow together!

founded 1 year ago
MODERATORS
top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 11 months ago* (last edited 11 months ago)

Holy hell no.

The code you provided could be risky because:

No Data Checking: It directly uses data from an API without checking if it's safe or correct.

Dynamic Properties: Adding properties to an object on the fly can make the code hard to manage.

External Data Dependency: Relying on API data structure without checks can lead to issues if the API changes.

If you don’t know the data is safe (it’s not), it’s a lot better to use an associative array. Additionally, if it’s from a json, it’s quicker and easier to iterate over array. Don’t make it complicated for no reason.