Search code examples
phpoopsyntaxnamespacescomments

Can we add php comments before declaring namespace


I would like to add PHP comments before declaring namespace.

<?php
    /*
     *  This is custom namespace
     *  Purpose : to give an example of namespace
    **/

    namespace myNameSpace{
        class myNewClass{
            /*
                code
            */
        }
    }
?>

This does not throw any errors but I am not sure if this will work in higher PHP versions. I am using 5.3.3.

For me using below code is just boring

<?php   
    namespace myNameSpace{
        /*
         *  This is custom namespace
         *  Purpose : to give an example of namespace
        **/

        class myNewClass{
            /*
                code
            */
        }
    }
?>

Solution

  • PHP's parser ignores comments. You can safely place them before or after namespace declarations without concern.