Cannot define NS constants after a class directive

Issue #16 open
Benoît Ryder
created an issue

Constants defined after the definition of a class (or exception) are put in this class. Thus, it is not possible to define namespace constants after defining a class.
For instance:
.. php:namespace:: MyNs
.. php:class:: MyClass
.. php:const:: CONSTANT
Will define {{{MyNs\MyClass}}} and {{{MyNs\MyClass::CONSTANT}}} (instead of {{{MyNs::CONSTANT}}}) and it is not possible to define {{{CONSTANT}}} not in {{{MyClass}}} except by moving it above.

The following patch fixes the issued but has not been checked for side-effects:
--- 2011-05-17 16:51:20.000000000 +0200
+++ 2011-05-17 17:10:50.000000000 +0200
@@ -317,6 +317,7 @@

 def after_content(self):
     self.env.temp_data['php:in_class'] = False
  • self.env.temp_data['php:class'] = None

    def before_content(self):
    self.env.temp_data['php:in_class'] = True

Comments (2)

  1. Mark Story

    One issue with this change is that it breaks non-indented class constants. There is a bit of ambiguity there though, as without indenting the constants. As you pointed out its currently not possible to make global constants that follow a class. Two possible solutions I can think of are:

    • Create a new directive for class contants .. php:classconst::
    • Require that class constants contain the class name prefix .. php:const:: ClassName::CONST . Constants without Class:: would be treated as global constants.

    I think of the two solutions I can think of, the classname prefix is the least troublesome. It doesn't require yet another directive to be added, which I like.

  2. Log in to comment