{"id":8808,"date":"2020-05-25T11:00:23","date_gmt":"2020-05-25T02:00:23","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8808"},"modified":"2020-05-22T18:56:52","modified_gmt":"2020-05-22T09:56:52","slug":"php-static-methods","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8808","title":{"rendered":"PHP Static methods"},"content":{"rendered":"\n<p>I will talk about static methods usages in php with some code samples. Lets get started.<\/p>\n\n\n\n<p>Here is a sample, calling static function outside of the class.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nclass welcome {\n  public static function sayHi() {\n    echo \"Welcome!\";\n  }\n}\n\n\/\/ we can like this -> className::methodName()\nwelcome::sayHi();\n?><\/code><\/pre>\n\n\n\n<p>We can also call within the class like this using <strong>self::<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nclass welcome {\n\tpublic static function sayHi() {\n\t\techo \"Welcome!\";\n\t}\n\tpublic function msg() {\n\t\tself::sayHi();\n\t}\n}\n\n$hi = new welcome();\n$hi->msg();\n?><\/code><\/pre>\n\n\n\n<p>You can also call static methods from another class like this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nclass welcome {\n  public static function sayHi() {\n    echo \"Welcome!\";\n  }\n}\n\nclass anotherClass {\n  public function msg() {\n    welcome::sayHi();\n  }\n}\n\n$var = new anotherClass();\n$var->msg();\n?><\/code><\/pre>\n\n\n\n<p>You can choose any ways depending upon the situations, the result will still be the same.<\/p>\n\n\n\n<p><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\">By Yuuma<\/font><\/font><\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8808\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8808\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"PHP Static methods\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8808\" data-text=\"PHP Static methods\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8808\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8808\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>I will talk about static methods usages in php with some code samples. Lets get started. Here is a sample, cal [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8808"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8808"}],"version-history":[{"count":4,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8808\/revisions"}],"predecessor-version":[{"id":8814,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8808\/revisions\/8814"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}