@@ -36,6 +36,15 @@ class Create extends AbstractCommand
36
36
*/
37
37
public const CREATION_INTERFACE = 'Phinx\Migration\CreationInterface ' ;
38
38
39
+ // PHP keywords from https://www.php.net/manual/en/reserved.keywords.php
40
+ private array $ keywords = [
41
+ 'abstract ' , 'and ' , 'array ' , 'as ' , 'break ' , 'callable ' , 'case ' , 'catch ' , 'class ' , 'clone ' , 'const ' ,
42
+ 'continue ' , 'declare ' , 'default ' , 'die ' , 'do ' , 'echo ' , 'else ' , 'elseif ' , 'empty ' , 'enddeclare ' , 'endfor ' ,
43
+ 'endforeach ' , 'endif ' , 'endswitch ' , 'endwhile ' , 'eval ' , 'exit ' , 'extends ' , 'final ' , 'finally ' , 'for ' , 'foreach ' ,
44
+ 'function ' , 'global ' , 'goto ' , 'if ' , 'implements ' , 'include ' , 'include_once ' , 'instanceof ' , 'insteadof ' , 'interface ' ,
45
+ 'isset ' , 'list ' , 'namespace ' , 'new ' , 'or ' , 'parent ' , 'private ' , 'protected ' , 'public ' , 'return ' ,'static ' ,
46
+ ];
47
+
39
48
/**
40
49
* {@inheritDoc}
41
50
*
@@ -167,6 +176,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
167
176
168
177
$ path = realpath ($ path );
169
178
$ className = $ input ->getArgument ('name ' );
179
+ if ($ className !== null && in_array (strtolower ($ className ), $ this ->keywords )) {
180
+ throw new InvalidArgumentException (sprintf (
181
+ 'The migration class name "%s" is a reserved PHP keyword. Please choose a different class name. ' ,
182
+ $ className
183
+ ));
184
+ }
185
+
170
186
$ offset = 0 ;
171
187
do {
172
188
$ timestamp = Util::getCurrentTimestamp ($ offset ++);
0 commit comments