Re: runtime access to static variable
| From: | Nathan Rixham | Date: | Thu, 18 Dec 2008 02:48:50 +0000 |
| Subject: | Re: runtime access to static variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-284763@lists.php.net to get a copy of this message | ||
Jack Bates wrote:
Yup I follow, been here myself too; infact doing very similar at the mo making an event handler / listener for the hell of it! anyhow.. stick this in you're DeployTask and run it :p protected function execute($arguments = array(), $options = array()) { // you're existing code here up to.. $job->pid = getmypid(); $thisClass = new ReflectionClass( get_class($this) ); $steps = $thisClass->getStaticPropertyValue('STEPS'); while ($job->step < count($steps)) {this does beg the question why don't you know the classname at runtime.. seems to be a slight design flaw and may make sense for you to post the full problem (you must have chosen to implement this for a reason..)The full problem is: I started off with a "DeployTask" for deploying a new instance of my web project to DreamHost: http://cgi.sfu.ca/~jdbates/tmp/php/200812170/DeployTask.class.phps (It is a "task" in the symfony framework, but basically the DeployTask::execute() method gets called) The task takes about thirty minutes to run, so I broke it up into steps. After each step, it updates a database row so that a user who started the task through a web interface can monitor its progress. Great so far. Now I decided to create an "UpdateTask" for updating deployed instances to the latest version of my code: http://cgi.sfu.ca/~jdbates/tmp/php/200812170/UpdateTask.class.phps Of course it also takes a long time to run, so my first iteration just extends the DeployTask and defines different steps. UpdateTask inherits DeployTask::execute(), which drives the steps and updates the database. Unfortunately, in the inherited DeployTask::execute(), "self::$STEPS" does not refer to UpdateTask::$STEPS, it refers to DeployTask::$STEPS : (
$job->save();
call_user_func(array($this, $steps[$job->step]), $arguments, $options);
$job->step++;
}
$job->delete();
}
untested but should work :)