PHP class doesn't recognize this->method() -
when trying access method i've defined in php class within method in same class, following error:
parse error: syntax error, unexpected '->' (t_object_operator) in /var/www/
.../toc.php on line 57
previously, i'd these functions sitting outside of class, including them needed them. having moved them one, @ first thought must having issue this user having, instance of class, can call render method file no problems. commenting out line this->printtreearray($sectionprojects);
eliminates error. here's class:
<?php class toc{ private function printtreearray($sectionprojects){ echo "var tocnodes = [\n"; //print each section, loop print each one's problems $i = 0; foreach($sectionprojects $sectionproject){ if($i != 0){ echo ",\n"; } $project = $sectionproject->getproject(); //get due date mouseover text $due = $project->getduedate('f js, y h:i a'); $q = new projectproblemquery(); $projectproblems = $q->findbyrelprojectid($project->getid()); $pid = $i + 1; echo "{id: $pid, pid: 0, name: \"project $pid\", title: \"due: $due\", isparent: true, open: true}"; //print section's problem list $probid = 1; foreach($projectproblems $projectproblem){ echo ",\n"; $nodeid = ($pid * 10) + $j; echo "{id: $nodeid, pid: $pid, name: \"$pid.$probid\", url: \"#\", target: \"_top\"}"; $j++; } $i++; } echo"];\n"; } public function render($section){ if(! $section instanceof section){ echo "$section not instance of section!"; } else{ echo "<ul id=\"toctree\" class=\"ztree\"></ul>\n"; echo "<script type=\"text/javascript\">\n"; $sectionprojects = $section->getsectionprojects(); this->printtreearray($sectionprojects); echo "$(document).ready(function () { $.fn.ztree.init($(\"#toctree\"), setting, tocnodes); });"; echo "</script>"; } } }
this first time asking question on - i've been able find answers coding dilemmas, 1 has me baffled. realize there's lot of not-elegant stuff going on in class, if there's point of style can use avoid sort of error in future, i'd appreciate getting learn it.
you should use $this
instead of this
.
Comments
Post a Comment