alex_r 0 Posted February 13, 2017 Report Share Posted February 13, 2017 (edited) 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 February 13, 2017 by alex_r Quote Link to post Share on other sites
alex_r 0 Posted February 13, 2017 Author Report Share Posted February 13, 2017 http://stackoverflow.com/questions/9882145/the-best-way-to-include-a-file-across-multiple-files-in-php-for-inheritance -- The selected answer to this question (answered by deceze) answers this, I think? Quote Link to post Share on other sites
Larry 428 Posted February 14, 2017 Report Share Posted February 14, 2017 Strange...I just tested it myself and it worked fine. The approach in the Stack Overflow link should work but shouldn't be necessary. Quote Link to post Share on other sites
alex_r 0 Posted February 15, 2017 Author Report Share Posted February 15, 2017 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'); Quote Link to post Share on other sites
Larry 428 Posted February 16, 2017 Report Share Posted February 16, 2017 Hmm...computers are sometimes a mystery! Gla it's working now, though. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.