title: PHP Class Cheat Sheet tags: php class cheat-sheet The general idea of a cheat sheet is to give minimal examples, enough to remember things. For example the syntax for one class deriving from another is different between [C++](/lang/cpp), [Java](/lang/java), [Python](/lang/python) and [PHP](/lang/php). ```php name(); } } $a = new MyClass(); $a->hello(); # use -> to refer to members if( $a->am_I_happy(0,"") ) { echo "happy\n"; } $fname = "hello"; $a->$fname(); # we can use strings to refer to member functions if( method_exists($a,$fname) ) { $a->$fname(); } $x = "hello NAME, are you NAME?"; $y = preg_replace_callback('/N\w*E/',[$a,"name"],$x); echo "$x\n$y\n"; ```