---
title: "Klassproblem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/14632-klassproblem"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Swey"
published: "2000-07-07T11:49:00.000Z"
updated: "2000-07-07T12:34:00.000Z"
replies: 2
views: 344
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/14632-klassproblem"
---

# Klassproblem

## #1 — Swey, 2000-07-07T11:49Z

```
<?
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?

Permalänk: https://www.webforum.nu/p/14632

## #2 — nicclas, 2000-07-07T12:13Z

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/>

Permalänk: https://www.webforum.nu/p/311371

## #3 — Swey, 2000-07-07T12:34Z

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

Permalänk: https://www.webforum.nu/p/311372

---

Tråden på webben: https://www.webforum.nu/amne/php/14632-klassproblem
