webForumDet fria alternativet

Klassproblem

PHPur PHP

2 svar · 339 visningar · startad av Swey

Medlem sedan apr. 20003 971 inlägg
Frågan#1
<?
class ForumClass
{
	var $Title, $Body;

	function ForumClass()
	{
		$this->$Title = "Titel";
		$this->$Body = "Kropp";
	}

	function Title()
	{
		echo $this->$Title;
	}

	function Body()
	{
		echo $this->$Body;
	}
}
$Forum = new ForumClass;
?>

<html>
<head>
<title><?php $Forum->Title() ?></title>
</head>
<body>
<?php $Forum->Body() ?>
</body>
</html>

Denna kod hanterar båda variablerna som SAMMA variabel och skriver därför ut samma sak som både titel och kropp. Har även provat att deklarera $Title och $Body på egna rader men det hjälper inte.

Bugg?

------------------
/mvh Swey
Programmera PHP

Medlem sedan feb. 20001 050 inlägg
#2

Giv akt på $-tecket efter $this! Så här så fungerar det:

<?
class ForumClass{
  var $Title, $Body;
  function ForumClass(){
    $this->Title = "Title";
    $this->Body = "Kropp";
  }
  function Title(){
    echo $this->Title;
  }
  function Body(){
    echo $this->Body;
  }
}
$Forum = new ForumClass;
?>

<html>
<head>
<title><?php $Forum->Title() ?></title>
</head>
<body>
<?php $Forum->Body() ?>
</body>
</html>

/nicclas @ http://www.nic-sys.se/

Medlem sedan apr. 20003 971 inlägg
#3

Ah, tack... lätt att missa sånt ;)

------------------
/mvh Swey
Programmera PHP

134 ms totalt · 3 externa anrop · v20260731065814-full.4bcf49fe
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
131 ms — hämta tråd, inlägg och bilagor (db)