Skip to content
UniKit

Field list to PHP code

One field per line (name:int, title:string, price:decimal(10,2)?, status:enum('a','b')) with optional length, `?` for nullable, `primary` for the primary key and `#` for comments. Output is a PHP array (return [...] schema description), a PHP class (properties, getters/setters and toArray()) or a Doctrine annotated entity (#[ORM\Column]). Unknown types throw invalid-type and bad field names throw invalid-field.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Input

Result

The result can be copied directly.

Write one field per line (name:int) to generate PHP code

Characters: 0 · Fields: 0 · Nullable fields: 0 · Primary keys: 0

What this tool does

  • Generate an entity skeleton from a field list in a spec.
  • Turn an API field table into a PHP array schema or Doctrine entity.
  • Add getters/setters and toArray() to legacy projects.

Example

Input

id:int primary
name:string
price:decimal(10,2)? # price

Output

<?php

// 由字段清单生成的表结构描述(表名:generated)
return [
    'id' => ['type' => 'int', 'sql' => 'int', 'nullable' => false, 'primaryKey' => true, 'autoIncrement' => true, 'default' => null],
    'name' => ['type' => 'string', 'sql' => 'string', 'nullable' => false, 'default' => null],
    'price' => ['type' => 'float', 'sql' => 'decimal(10,2)', 'length' => 10, 'nullable' => true, 'default' => null, 'comment' => 'price'],
];

The output is skeleton code (properties, accessors, array schema) without business logic; types map to PHP scalars: int / float / bool / string / array / mixed.

Frequently asked questions

Which type spellings are supported?

Common SQL / PHP type names: int, bigint, tinyint, decimal(10,2), float, bool, string, varchar(64), text, enum('a','b'), json, datetime and more. Add `?` for nullable and `primary` to mark the primary key (integer primary keys get autoIncrement).

How do comments work?

Start a comment with `#` at the end of a field line; it lands in the PHP docblock, Doctrine options and the array comment field. A whole line starting with `#` is skipped.

Array style or class style?

Use array style when you only need field metadata (validation, migrations, docs), class style when you want to work with objects, and the Doctrine style for ORM projects.

Does it connect to a database or run SQL?

No. This is a pure text code generator: no database connection, no SQL execution, everything happens locally in the browser.

Keywords:field to phpgetter setter

Related tools