\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Waleed Mohamed} \pdfinfo{ /Title (php-object-oriented-programming.pdf) /Creator (Cheatography) /Author (Waleed Mohamed) /Subject (PHP: Object-Oriented Programming Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{PHP: Object-Oriented Programming Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Waleed Mohamed} via \textcolor{DarkBackground}{\uline{cheatography.com/141114/cs/30177/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Waleed Mohamed \\ \uline{cheatography.com/waleed-mohamed} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 16th December, 2021.\\ Updated 16th December, 2021.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Class}} \tn % Row 0 \SetRowColor{LightBackground} Define Class & class class\_name \{ \} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Define property & var \$proberty\_name ; \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Define method & function fun\_name() \{....\} \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Instances}} \tn % Row 0 \SetRowColor{LightBackground} Define Instance & \$Student1 = new student; \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} set value to proberty & \$student1-\textgreater{}firstName = "ex"; \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} calling object function & \$student-\textgreater{}getName(); \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Refer to the instance & \$this-\textgreater{}name; \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.54924 cm} x{2.33427 cm} x{1.69349 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Visibility modifiers}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Public} & accessed from anywhere & var \seqsplit{\$proberty\_name;} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Protected} & accessed only from this class and subclasses & Protected \seqsplit{\$proberty\_name;} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{Private} & accessed from inside the class only & Private \seqsplit{\$proberty\_name;} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.69218 cm} x{3.28482 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Inheritance}} \tn % Row 0 \SetRowColor{LightBackground} Define Subclass & class child extends parent \{\} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{static modifier}} \tn % Row 0 \SetRowColor{LightBackground} Static property & public static \$property\_name ; \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Class constant & public const \seqsplit{CONSTANT\_NAME\_UPPERCASE;} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Calling Static\textbackslash{}constant property from inside the class & \seqsplit{self::\$property\_name;} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} Calling Static\textbackslash{}constant property from outside the class & \seqsplit{class\_name::\$property\_name;} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} Inheritance & Static property is shared variable between class and its sub classes , any change in one of them will change the others. \tn % Row Count 16 (+ 6) % Row 5 \SetRowColor{white} Calling parent class static method & \seqsplit{parent::method\_name();} \tn % Row Count 18 (+ 2) % Row 6 \SetRowColor{LightBackground} Late static Binding & \seqsplit{static::\$property\_name;} \{\{nl\}\} to allow static property inheritence and don't bind static property to first self use only \tn % Row Count 25 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Magic Methods}} \tn % Row 0 \SetRowColor{LightBackground} Magic method & -Magic methods are special methods which override PHP's default's action when certain actions are performed on an object. \{\{nl\}\}-Must be Public.\{\{nl\}\}-use \_\_ before method name. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Constructor method & Method will be called each new instance is created\{\{nl\}\}public function \seqsplit{\_\_construct(\$arg1='Default} value',\$arg2....)\{\{nl\}\}public function \_\_construct(\$args={[}{]})) \tn % Row Count 13 (+ 6) % Row 2 \SetRowColor{LightBackground} Destructor method & Method will be called when the last refrence to instance is destroyed\{\{nl\}\}public function \_\_destruct()\{\{nl\}\}use {\bf{unset(\$instance)}} method to destroy the instance. \tn % Row Count 20 (+ 7) % Row 3 \SetRowColor{white} Clone method & Method will be called when you use clone keyword \$ins1 = clone \$ins2;\{\{nl\}\}method will copy all Instance data to another instance\{\{nl\}\}function \_\_clone()\{\} \tn % Row Count 26 (+ 6) % Row 4 \SetRowColor{LightBackground} auoload method & Method will be called when PHP encounters an unkown class\{\{nl\}\}-Define a function : function my\_autoload()\{\}\{\{nl\}\}-Register autoload in php SPL : \seqsplit{spl\_autoload\_register('my\_autoload')} \tn % Row Count 33 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Overloading}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Dynamic Proberties \newline % Row Count 1 (+ 1) when you get the value of undefined property - \textgreater{} error notice, \newline % Row Count 3 (+ 2) But when you set the value of undefined property -\textgreater{} it will define and set \newline % Row Count 5 (+ 2) Example: \newline % Row Count 6 (+ 1) Class student \{ \newline % Row Count 7 (+ 1) \} \newline % Row Count 8 (+ 1) \$s1 = new student ; \newline % Row Count 9 (+ 1) echo \$s1-\textgreater{}name; //error \newline % Row Count 10 (+ 1) \$s1-\textgreater{}name = waleed //set dynamic property ; \newline % Row Count 11 (+ 1) echo \$s1-\textgreater{}name; //waleed% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Compare objects}} \tn % Row 0 \SetRowColor{LightBackground} == & return true if tow instance : \{\{nl\}\} - have the same refrence\{\{nl\}\}- or have matching proberties \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} === & return true only if Instances have the the same refrence \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions for Class}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{get\_declared\_classes()} & return array of decleared classes in the file \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{class\_exists(\$string)} & take a string:ClassName and return true if the class is decleared \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions for Instance}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{get\_class(\$object)} & return object class name \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} is\_a(\$object,\$ClassName) & return true if the \$object has the same class name as the \$className \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions for Proberties}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{get\_class\_vars(\$string)} & return list of proberties defined in this class using class name \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{get\_object\_vars(\$object)} & return list of proberties defined in this class using object instance \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{property\_exists(\$mixed},\$string) & return true if the proberty name exist on the (class or object instance) \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{get\_class\_methods(\$mixed)} & return list of methods defined in this class using class name \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{method\_exists(\$mixed},\$string) & return true if the method name exist on the (class or object instance) \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.14011 cm} x{2.83689 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions For Inheritance}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{get\_parent\_class(\$mixed)} & return the parent class for (ClassName or object Instance) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{is\_subclass\_of(\$mixed},\$string) & return true if the (ClassName or object Instance) is child of the given class name \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{class\_parents(\$mixed)} & get all parent classes of this (ClassName or object Instance) \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{function for static binding}} \tn % Row 0 \SetRowColor{LightBackground} get\_class() & return the parent class use this function \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{get\_called\_class()} & return the actual runtime class \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}