$lineContent) { if (isNamespaceDeclaration($lineContent)) { $position = $pos; } } return $position; } function isNamespaceDeclaration($lineContent) { return strpos($lineContent, "namespace ") === 0; } // get the contents of that file and split into lines // find the line with the namespace declaration and remove it // insert it into the second position // write all the lines back to the file