{"id":4039,"date":"2022-01-25T14:30:50","date_gmt":"2022-01-25T14:30:50","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=4039"},"modified":"2022-02-17T07:13:46","modified_gmt":"2022-02-17T07:13:46","slug":"create-a-new-class","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/classes\/create-a-new-class","title":{"rendered":"Create a new class"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Define the class<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>class MyClass\n{\n  public $PropertyA, $PropertyB, $PropertyC;\n\n  function MyFunctionName()\n  {\n    return \"Value is $this-&gt;PropertyA.\";\n  }\n\n}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Use the class<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyObject = new MyClass();\n\n  $MyObject-&gt;PropertyA = \"abc\";\n\n  echo $MyObject-&gt;MyFunctionName();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Constructor<\/h4>\n\n\n\n<p>The constructor function is optional, if defined it is automatically called when an object is instantiated.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class MyClass\n{\n  public $PropertyA, $PropertyB, $PropertyC;\n\n  \/\/*********************************\n  \/\/********** CONSTRUCTOR **********\n  \/\/*********************************\n  function __construct()    \/\/&lt;&lt;&lt;You can optionally add arguments to be passed to this function when the class is created using new, e.g. function __construct($PropertyA, $PropertyB)\n  {\n    \n    $this->PropertyA = \"abc\";\n\n  }\n\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Define the class Use the class Constructor The constructor function is optional, if defined it is automatically called when an object is instantiated.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[315],"tags":[],"class_list":["post-4039","post","type-post","status-publish","format-standard","hentry","category-classes"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=4039"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4039\/revisions"}],"predecessor-version":[{"id":4047,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4039\/revisions\/4047"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=4039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=4039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=4039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}