function addEntryT($short, $name){ // Titel
$this->entries[count($this->entries)] = & new menuentry($short, $name, 1);
}
you are using references..
see here: http://us4.php.net/manual/en/language.references.php
namely the first two comments (newest on top)...they appear to be related to your issue.
and I quote.."Re-using variables which were references before, without unsetting them first, leads to unexpected behaviour."
are you experiencing "unexplained behavior"?
Prior to php5, when you assigned an object to a variable, or passed it to a function, it was actually copied into the variable or function. php5 uses the zend engine2, which copies by reference, rather than copying. This means that in php5 if several variables point to the same object, and you update the object, each variable can access the updated object contents. In php4, each variable would simply have a copy of the outdated object.
I would venture a guess that likely that is the main difference that you are experiencing trying to revert back to php4..
Just an educated guess though...I will look at the code a bit more and see..
]]>if you know php and especially know the difference in php4 and php5, then please have a look at this chaos:
<?
class menuentry{
var $name;
var $short;
var $linksSubmenu;
var $isTitle;
var $submenu;
function menuentry($Tshort, $Tname, $TisTitle){
$this->short = $Tshort;
$this->name = $Tname;
$this->linksSubmenu = 0;
$this->isTitle = $TisTitle;
}
function addSubmenu($submenu){
$this->submenu = $submenu;
$this->linksSubmenu = 1;
}
function linksSubmenu(){
return $this->linksSubmenu;
}
}
class menu
{
var $entries;
function addEntryT($short, $name){ // Titel
$this->entries[count($this->entries)] = & new menuentry($short, $name, 1);
}
function addEntry($short, $name){ // normal
$this->entries[count($this->entries)] = & new menuentry($short, $name, 0);
}
function getEntry($short){
$liste = $this->entries;
for($a = 0; $a < count($liste); $a++) {
if($liste[$a]->short==$short){
return $liste[$a];
}
}
}
}
function MenuAusgabe($menu, $baseurl){
$alles=$menu->entries;
for($i=0; $i<count($alles); $i++){
if($alles[$i]->isTitle==1){ // TITEL
echo "<div>".$alles[$i]->name."</div>n";
}
elseif($alles[$i]->short==$_GET['show']){ // AKTIV
echo "t<a class='aktiv' href='".$baseurl."?show=".$alles[$i]->short."'>".
$alles[$i]->name."</a> n";
if($alles[$i]->linksSubmenu==1){ // SUBMENU EXISTIERT!
$submenu=$alles[$i]->submenu;
$hermitdendaten=$submenu->entries;
for($s=0; $s<count($hermitdendaten); $s++){
if($hermitdendaten[$s]->short==$_GET['subcat']){
echo "tt<a class='aktivsubmenu' href='".$baseurl."?show=".$alles[$i]->short."&subcat=".$hermitdendaten[$s]->short."'>".$hermitdendaten[$s]->name."</a> n";
}else{
echo "tt<a class='submenu' href='".$baseurl."?show=".$alles[$i]->short."&subcat=".$hermitdendaten[$s]->short."'>".$hermitdendaten[$s]->name."</a> n";
}
}
}
}else{ // NICHT AKTIV
echo "t<a href='".$baseurl."?show=".$alles[$i]->short."'>".
$alles[$i]->name."</a> n";
}
}
}
?>
<!-- MENU ---------------------------- MENU -->
<?
/* alles für das menu ist unter functions/menu.php deklariert */
define('FUNCTIONS_DIR', '/home/httpd/vhosts/calcutta-project.ch/httpdocs/functions/');
require_once(FUNCTIONS_DIR.'menu.php');
/* Build Menu: */
$hauptmenu = new menu;
$hauptmenu->addEntryT("titel1", "Calcutta Project Basel");
$hauptmenu->addEntry("partner", "Partner");
$hauptmenu->addEntry("sponsoren", "Sponsors");
$hauptmenu->addEntryT("titel2", "NGO's");
$hauptmenu->addEntry("ngosCH", "Switzerland");
$Eintrag_ngosCH = $hauptmenu->getEntry("ngosCH");
$ngosCH = new menu;
$ngosCH->addEntry("umwelt", "Environnement");
$ngosCH->addEntry("armut", "Poverty");
$Eintrag_ngosCH->addSubmenu($ngosCH);
$hauptmenu->addEntry("ngosE", "World");
$Eintrag_ngosE = $hauptmenu->getEntry("ngosE");
$ngosE = new menu;
$ngosE->addEntry("umwelt", "Environnement");
$ngosE->addEntry("armut", "Poverty");
$Eintrag_ngosE->addSubmenu($ngosE);
$hauptmenu->addEntryT("titel3", "India");
$hauptmenu->addEntry("calcutta", "Calcutta");
$hauptmenu->addEntry("india", "General");
/*
echo "<pre>";
echo print_r($hauptmenu);
echo "</pre>";
*/
/* WRITE MENU */
echo "<div class='sideBox LHS'>";
MenuAusgabe($hauptmenu, "/pub/links.en.php");
echo "</div>";
?>
<!-- MENU ---------------------------- MENU -->
THE DIFFERENCE IN EXECUTION:
$Eintrag_ngosE = $hauptmenu->getEntry("ngosE");
$ngosE = new menu;
$ngosE->addEntry("umwelt", "Environnement");
$ngosE->addEntry("armut", "Poverty");
$Eintrag_ngosE->addSubmenu($ngosE);
or better:
function getEntry($short){
$liste = $this->entries;
for($a = 0; $a < count($liste); $a++) {
if($liste[$a]->short==$short){
return $liste[$a];
}
}
}
is only done under php5 (archlinux) correctly (in redhat ... running php4, it is simply ignored (no error, no warning, no nothing ... but also no submenus!))
any ideas, how can i make my code php4 compatible? (i searched the net, but there are only solutions how to make your php4-code working under php5 and not the other way round - :twisted: :evil: :twisted: )
any input welcome 8)
]]>