Jump to content
Larry Ullman's Book Forums

Recommended Posts

abstract class Shape
{
	// No attributes to declare
	// No constructor or destructor defined here
	
	// Method to calculate and return the area.
	abstract protected function getArea();
	
	// Method to calculate and return the perimeter.
	abstract protected function getPerimeter();
}
// End of Shape class.

Next I declared "Triangle" class

<?php
class Triangle extends Shape
{
	// Declare the attributes:
	private $_sides = array();
...

Then created the "abstract.php"

<!DOCTYPE html>

<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Triangle</title>
		<link href="css/style.css" rel="stylesheet">
	</head>
	
	<body>
	<?php
	# Script 6.3 - abstract.php
	// This page uses the Triangle class (Script 6.2), which is derived
	// from Shape (Script 6.1).
	
	// Load the class definitions
	require('Shape.php');
	require('Triangle.php');
	
	// Set the triangle's sides:
	$side1 = 5;
...

When I run abstract.php, it generates the following error

Fatal error: Class 'Shape' not found in C:~\Triangle.php on line 15

I don't understand why it's showing this error. Please help!

My PHP version is 5.6.12 using XAMPP Version 5.6.12

Edited by alex_r

Share this post


Link to post
Share on other sites

Strange...I just tested it myself and it worked fine. The approach in the Stack Overflow link should work but shouldn't be necessary.

Share this post


Link to post
Share on other sites

Am not sure what happened too. 

I tested using "include", which worked and later i used "require" and now seems to work fine no problem. I don't know what the problem is.

	// Load the class definitions
	/*
	include('Shape.php');
	include('Triangle.php');
	*/
	
	require('Shape.php');
	require('Triangle.php');

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...