webForumDet fria alternativet

Klassproblem

2 svar · 339 visningar · startad av Swey

SweyMedlem sedan apr. 20002 000 inlägg
#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

nicclasMedlem sedan feb. 20001 061 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/

SweyMedlem sedan apr. 20002 000 inlägg
#3

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

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

Genererad på 378 ms · cache AV · v20260730165559-full.f96bc7eb