nikic / PHP-Parser

A PHP parser written in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I add a namespace to a PHP file?

ajiho opened this issue · comments

I have a PHP file helpers.php

<?php

if (!function_exists('abc')) {

    function abc(array $array)
    {
        //...
    }
}

I want to add a namespace to it

Just like this

<?php

namespace MyNamespace\Helper;


if (!function_exists('abc')) {

    function abc(array $array)
    {
        //...
    }
}

I have searched for relevant documents and tried for a long time, but failed. Can you give me some guidance? Thank you again

I think something along these lines should do it?
$stmts = [new Namespace_(new Name('MyNamespace\Helper'), $stmts)];

I think something along these lines should do it? $stmts = [new Namespace_(new Name('MyNamespace\Helper'), $stmts)];

Thank you for your prompt. I have successfully added the namespace. This issue can be closed. Thank you again