Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9030867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:35:47+00:00 2026-06-16T07:35:47+00:00

Doing some OO PHP. I’m getting undefined variables on line 11 and 31 and

  • 0

Doing some OO PHP. I’m getting undefined variables on line 11 and 31 and I’m not sure why.

http://pastebin.com/D0rNWdn3

<?php 

    class geometricObject {
        private $color;

        public function __construct($color){
            $this->color = $color;
        }

        public function getColor(){
            return $color;
        }

        public function setColor($color){
            $this->color = $color;
        }
    }

    class circle extends geometricObject {
        private $radius;

        public function __construct($radius, $color){
            parent::__construct($color);
            $this->radius = $radius;
        }

        public function getRadius(){
            return $radius;
        }

        public function getArea(){
            return (pi() * pow($radius, 2));
        }

        public function getSurfaceArea(){
            return (2 * pi() * $radius);
        }

        public function setRadius($radius){
            $this->radius = $radius;
        }
    }

?>

<?php 

    include_once 'templates/classes.php';

    $myCircle = new circle(10, "green");

    $circleArea = $myCircle->getArea();

    $color = $myCircle->getColor();

    include_once 'output.php';

?>

<html>
<body>

<?php echo $circleArea; echo $color; ?>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:35:48+00:00Added an answer on June 16, 2026 at 7:35 am

    You’re getting the error because $color is undefined within the method scope. You only pass the $color argument to the constructor and the setColor method.

    To access it in other class methods you would use $this->color not $color

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a PHP programmer doing some BASH scripting and I'm not sure how global
So I'm doing some maintenance on a PHP site that is using $_SESSION variables.
I'm doing a style.php CSS file so I can use some dynamic variables in
I am currently doing some basic PHP and I am getting products from mysql
Lately i been doing some work on my MySql class in php and as
I'm doing some SOAP exercises based on this example: http://www.vankouteren.eu/blog/2009/03/simple-php-soap-example/ But, I cannot get
after doing some research i'm still not sure if using mysql with .net desktop
I am doing some maintenance work on an older system that is running PHP
I`m doing some web.config modifications with SPWebConfigModification class. When adding them to WebApplication and
I'm doing some PHP stuff on an Ubuntu server. The path I'm working in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.