How can I specify an argument type to take any enum value? Something like function processEnum(enum $value) would be ideal, however nothing seems to exist? Additionally it would be nice to separate backed vs non-backed enums or additionally backed types; enums that are backed as strings for example. Answer All enums implement the UnitEnum interface, and backed enums (those with
Tag: types
How To Declare Traversable Type?
There are multiple typehints in PHP, more now in PHP 8, and even more with Psalm. But what about declaring the type, rather than hinting the expected type? I have a interface Collection extends Traversable, and I need to declare that it is a traversable of type Abc. How can I do that, so that PHPDoc or Psalm know that
Symfony 5.1 – Dynamically add a CustomType field before submitting
My problem is not that simple I will try to summarize as best as I can. Let’s say I have an entity Vehicle which is related to an entity Engine. Engine entity is an abstract type which is implemented by 2 classes : ElectricEngine and GasEngine. I want to create a form for Vehicle which will create a vehicle and
How can I auto populate previously uploaded file using html and php?
I want my previously uploaded file to be automatically selected while I am editing details which also include file upload. I have used value attribute as in other types. But this doesn’t work. I have to select the required file again while I am editing details. No file is selected as default while editing. I want to edit other details
How to add options to a Symfony Form field?
I am rather new to PHP & Symfony, and am struggling with the form options: I have the following, simple code: I get an error because the format is not an option of TextType, but I cannot find a way to add my own options (But I know this is possible, from the others posts I read) I have read
Phalcon ORM – integer field id is string after save
I’m using Phalcon for my current project and i’m seeing some strange behaviour with the type casting. I have this model class Customer extends Model { protected $id; protected $name; } In …
Laravel / PHPUnit: Asserting sameness of two models
When integration testing (using a database) in Laravel. What is the best way to assert that two instances of the same Eloquent model are the same? AssertEquals $model $model Simply using ->assertEquals($modelOne, $modelTwo); wont work as even if they are the same PHPUnit checks class properties such as wasRecentlyCreated and sometimes model ids can be a string or an integer.
With strict types enabled, array_map converts types anyways
I’ve came across a really interesting bug in PHP 7.0.11 where declare(strict_types=1); enabled does not make the array_map() nor array_walk() aware of strict types. I read somewhere that by enabling strict types PHP also uses strict types in core functions, but this is not the case. Look at this example code, it should throw TypeError exception: The var_dump result is:
MySQL: dates before 1970
I’m working on a church site which has many events before 1970, these events starts from 1001 to today, how can I store the dates in MySQL? This works fine only for dates after 1970, how can I store dates before this year? What kind of datatype should I have in MySQL? Now I’ve set my column to date type