Question: ```
<?php
class A
    {
        public $attribute1;
        function operation1()
            {
                echo 'operation1';
            }
}
$a = new A();
$a->attribute3 = 10;
echo $a->attribute3;

```

when i run above script, It shows: `10`

Question:

There is no declaration of `attribute3` in `class A`? why i can still use it `$a->attribute3 = 10;`?

Answer: 
As @Hamish said ... because that is how PHP works. 

Just like you can say:

```
$a = "hello";

```

and create a property in a function's scope or in the global scope you can use

```
$obj->a = "hello";

```

to create a property in the $obj instance's scope. 

If this is undesired behavior you can throw an exception using the \_\_get and \_\_set magic methods. 

```
class A{
   public $property1;

   public function __get($property){
          throw new Exception($property." does not exist in ".__CLASS__);
   }
   public function __set($property, $value){
          throw new Exception($property." does not exist in ".__CLASS__);

   }
}

```
In short: *because you can*.

PHP lets you define object attributes without declaring them in the class.

It's not an uncommon feature, e.g. python:

```
class Foo(object):
    pass
foo = Foo()
foo.bar = "Hi"
print foo.bar  # "Hi"

```