Q:

How to assign a value to public properties from outside of the class in PHP OOP

I want to assign a value to a property of an object. I think it should be something like this:
$object->property = "value";

So, in my case I do:
$circle_obj->radius = 4;

So, I expected that property radius should be 4. Unfortunately, this is not the case in my situation. Can you understand why?
Below you can see my code. 
<?php
    class BaseClass{

        public function calcSurface(){
                //empty method
        }
    }

    class Subclass_Circle extends BaseClass{
        public $radius;

        public function calcSurface(){
            global $radius;
            return M_PI * ($radius * $radius);
       }
    }

    $circle_obj = new Subclass_Circle();
    $circle_obj->radius = 4;
    echo "Oppervlakte van circle is: " . $circle_obj->calcSurface(); //ouput: 0
    echo "<br>";

    class Subclass_Square extends BaseClass{
        public $width;
        public $height;

        public function calcSurface(){
            global $width;
            global $height;

            return $width * $height;
       }
    }

    $square_obj = new Subclass_Square();
    $square_obj->width = 4;
    $square_obj->height = 4;
    echo "Oppervlakte van vierkant is: " . $square_obj->calcSurface(); //output: 0
?>

A:

You shouldn't be using global, but instead $this, like so:
public function calcSurface(){
  return M_PI * ($this->radius * $this->radius);
}

Check out the PHP OOP tutorial for more information.
And look at the variable scope tutorial to better understand the global keyword.

