---
title: "PHP och objektorientering..."
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/147789-php-och-objektorientering"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "swede"
published: "2006-06-07T08:31:09.000Z"
updated: "2006-06-07T10:32:36.000Z"
replies: 2
views: 364
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/147789-php-och-objektorientering"
---

# PHP och objektorientering...

## #1 — swede, 2006-06-07T08:31Z

Sitter och leker lite med PHP och objektorientering...

Har skapat en liten klass som följer:

```php
class book {
   private $ISBN;
   private $author;

   function getISBN() {
     return $this->$ISBN;
   }

   function setISBN($ISBN){
     $this->$ISBN = $ISBN;
   }

   function getAuthor(){
     return $this->$author;
   }

   function setAuthor($author){
     $this->$author = $author;
   }
 }
```

 

Sedan försöker jag använda den såhär:

```php
  include 'data.php';

  $books = new book();
  $books->setAuthor("johan");
  $books->setISBN("1112");

  echo $books->getAuthor();
```

 

Men då får jag följande fel meddelande:

```php
PHP Notice:  Undefined variable: author in /test/include/data.php on line 16
PHP Notice:  Undefined property:  book::$ in /test/include/data.php on line 16
```

 

Vad är detjag har tänkt fel?

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

## #2 — Peeer, 2006-06-07T09:09Z

```php
class book {
   private $ISBN;
   private $author;

   function getISBN() {
     return $this->ISBN;
   }

   function setISBN($ISBN){
     $this->ISBN = $ISBN;
   }

   function getAuthor(){
     return $this->author;
   }

   function setAuthor($author){
     $this->author = $author;
   }
}
```

Dvs inga $ framför variablerna inom klassen.

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

## #3 — swede, 2006-06-07T10:32Z

TACK!!!

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

---

Tråden på webben: https://www.webforum.nu/amne/php/147789-php-och-objektorientering
