Skip to content

Commit 50ab569

Browse files
authored
Added inheritance/extension doc
1 parent de8b34a commit 50ab569

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

doc/inheritance-extension.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[<-- Return to index](../README.md)
2+
# Inheritance/Extension
3+
4+
### How are classes inherited/extended?
5+
#### PHP
6+
Classes are extended by use of the `extends` keyword.
7+
```php
8+
<?php
9+
class myClass {
10+
private $foo;
11+
public function setFoo($value) {
12+
$this->foo = $value;
13+
}
14+
}
15+
16+
class myOtherClass extends myClass {
17+
public $bar;
18+
public function baz() {
19+
print "This is a unique method that myClass doesn't have";
20+
}
21+
}
22+
?>
23+
```
24+
#### Python
25+
Classes are inherited as they are defined:
26+
```python
27+
class myClass:
28+
foo = 1
29+
def setFoo(value):
30+
self.foo = value
31+
32+
class myOtherClass(myClass):
33+
bar = "apples"
34+
def baz():
35+
print "This method is unique to myOtherClass and isn't in myClass"
36+
```

0 commit comments

Comments
 (0)