How to get values from a Stripe\Collection JSON output

I’m working with Stripe in a PHP app. I’ve created a product and set prices for it via code. I added ‘lookup_key’ => value to each price. That all worked. When I use stripes lookup_keys command to get prices by that key, I do not know how to parse the output returned. Example price: $stripe->prices->create([… Read More How to get values from a Stripe\Collection JSON output

Unexpected behaviour with PHP trim() native function

Is this for real? Native PHP trim function uses the $char_double by default. I expected the $trimmed_single_double to be as $trimmed_matching_double. This code was tested on https://onlinephp.io/c/9799e2b3-6598-447b-9ca1-31218983d9e1 using (PHP 8.1.12). Feel free go check it out. I want to believe I’m doing something wrong. I’m nervous. Code (PHP 8.1.12) <?php $text_double = "\n text \n";… Read More Unexpected behaviour with PHP trim() native function

How to compare two datetime form Json data with the current datetime in PHP 8

I want to compare two DateTime from JSON data with the current DateTime. compare the start date & end date with the current date to data between these two dates. If dates do not match give 0 answer. $json = ‘[ { "type":"playlist", "id": "35", "start_datetime": "2022-09-28 09:48", "end_datetime": "2022-09-28 09:51" }, { "type":"asset", "id":… Read More How to compare two datetime form Json data with the current datetime in PHP 8

Enums extend or use traits (reusability)

I have enums that must have additional methods for translation purposes: <?php declare(strict_types=1); namespace App\Enums; enum GenderEnum: string { case MALE = ‘male’; case FEMALE = ‘female’; public function trans(): string { return trans(‘enums.’ . $this->value); } } This method is trans and it will be duplicated in all enums, how can I avoid duplication?… Read More Enums extend or use traits (reusability)

Why does 'iterator_to_array' give different results than foreach?

Suppose I have the following recursive function to turn an array into a Generator: function traverse(array $items): Generator { if (!empty($items)) { yield $items[0]; array_shift($items); yield from traverse($items); } } Running this function and iterating over the Generator through a foreach gives the expected result: $values = traverse([‘a’, ‘b’, ‘c’, ‘d’, ‘e’]); foreach ($values as… Read More Why does 'iterator_to_array' give different results than foreach?