Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Unknown Base Class results in uncompilable C++ due to (incorrect) undeclared variable #361

davidsklar opened this Issue · 1 comment

2 participants


A private static variable in a class which extends an unknown base class produces C++ that does not compile.

To reproduce, attempt to compile this class with hphp:


class Butter extends AClassThatDoesNotExist {

  private static $isChurning = false;

  private static function startChurning() {
    self::$isChurning = true;

CodeError.js contains:


which is correct about the UnknownBaseClass but incorrect about the UseUndeclaredVariable.

hphp fails with the following error:

/tmp/hphp_7kn0mT/php/home/david/peanut/Butter.cpp: In static member function \xe2\x80\x98static void HPHP::c_Butter::t_startchurning()\xe2\x80\x99:\n/tmp/hphp_7kn0mT/php/home/david/peanut/Butter.cpp:157: error: lvalue required as left operand of assignment\nmake[2]: *** [CMakeFiles/hpeanut.dir/php/home/david/peanut/Butter.cpp.o] Error 1\nmake[1]: *** [CMakeFiles/hpeanut.dir/all] Error 2\nmake: *** [all] Error 2\n

And indeed, the definition of startChurning() in Butter.cpp looks like this:

/* SRC: /home/david/peanut/Butter.php line 7 */
void c_Butter::t_startchurning() {
  STATIC_METHOD_INJECTION_NOMEM(Butter, Butter::startChurning);
  INTERCEPT_INJECTION("Butter::startChurning", null_array, r);
  false = true;

Note the "false" instead of something such as " g->s_Butter___isChurning" in the last line of that method.

If the $isChurning static variable is made public or protected instead of private, then CodeErrors.js still contains both errors (the correct UnknownBaseClass error and the incorrect UseUndeclaredVariable error) but the generated C++ compiles correctly. The generated startChurning() method looks like:

/* SRC: /home/david/peanut/Butter.php line 7 */
void c_Butter::t_startchurning() {
  STATIC_METHOD_INJECTION(Butter, Butter::startChurning);
  INTERCEPT_INJECTION("Butter::startChurning", null_array, r);
  c_Butter::os_lval(NAMSTR(s_sscce4235e, "isChurning")) = true;

We're closing out all bugs older than 2 months.

If this is still an issue, please re-open it, and in order of goodness:

  1. Give detailed repro steps
  2. Write a test case in hphp/tests/quick (run it with hphp/tests/run) and send the pull request
  3. Fix it in a pull request
@ptarjan ptarjan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.