Variabler

http://php.net/manual/en/language.variables.php

<?php

/**
* An example class with member variables
* http://www.phpdoc.org/
*/
class Book {

	public $author;
	private $title;
	protected $isbn;

	/**
	* @param String author , Example "J.K. Rowling"
	* @param String title , Example "Harry Potter and the Philosopher's Stone"
	* @param String isbn , Example "9788478888566"
	*/
	public function __construct($author, $title, $isbn) {
		$this->author = $author;
		$this->title = $title;
		$this->isbn = $isbn;
		
	}

	/**
	* @param Book other book to compare to
	* @return boolean return true if the books are the same
	*/
	public function isSame(Book $other) {
		if($this->author != $other->author) { 
			return false;
		}

		if($this->title != $other->title) { 
			return false;
		}

		if($this->isbn != $other->isbn) { 
			return false;
		}

		return true;
	}
}
//Testcase
$book = new Book("Daniel", "PHP unlimited", "123456");
$bookSame = new Book("Daniel", "PHP unlimited", "123456");
$bookOther = new Book("Daniel", "PHP unlimited 2", "123457");
 
assert($book->isSame($bookSame) == true);
assert($book->isSame($bookOther) == false);

Welcome to CoursePress

en utav Linnéuniversitets lärplattformar. Som inloggad student kan du kommunicera, hålla koll på dina kurser och mycket mer. Du som är gäst kan nå de flesta kurser och dess innehåll utan att logga in.

Läs mer lärplattformar vid Linnéuniversitetet

Student account

To log in you need a student account at Linnaeus University.

Read more about collecting your account

Log in LNU