Unknown Base Class results in uncompilable C++ due to (incorrect) undeclared variable
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:
<?php
class Butter extends AClassThatDoesNotExist {
private static $isChurning = false;
private static function startChurning() {
self::$isChurning = true;
}
}
CodeError.js contains:
[2,{"UseUndeclaredVariable":[{"c1":["\/home\/david\/peanut\/Butter.php",8,5,8,21]
,"d":"self::$isChurning"}
]
,"UnknownBaseClass":[{"c1":["\/home\/david\/peanut\/Butter.php",3,1,10,1]
,"d":"aclassthatdoesnotexist"}
]
}
]
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. http://www.hiphop-php.com/wp/?p=575
If this is still an issue, please re-open it, and in order of goodness:
- Give detailed repro steps
- Write a test case in hphp/tests/quick (run it with hphp/tests/run) and send the pull request
- Fix it in a pull request