{"id":10606,"date":"2020-02-17T12:15:57","date_gmt":"2020-02-17T12:15:57","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=10606"},"modified":"2022-05-08T12:07:20","modified_gmt":"2022-05-08T12:07:20","slug":"difference-between-public-private-protected-access-modifier-in-php-with-example","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/difference-between-public-private-protected-access-modifier-in-php-with-example\/","title":{"rendered":"Difference between Public, Private &#038; Protected Access Modifier in PHP with example"},"content":{"rendered":"\n<p><strong>Public Access Modifier:-<br><\/strong> Public Method or variable can be accessed from anywhere in the class. It means from inside or outside the class and child class also means anywhere you can access.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/a24929eb96d5254d666fc3d0741ffab1.js\"><\/script>\n\n\n\n<p><strong>Private Access Modifier:-<\/strong><br>Private Method or Property can be only access inside the class. If you can access from show error this is not accessible from outside. <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/1c432dba0267ddff4650566b6a5369ba.js\"><\/script>\n\n\n\n<p>Protected Access Modifier:-<\/p>\n\n\n\n<p><strong>Protected Access Modifier:-<br><\/strong> Protected Access Modifier Method or Property is only useful in case of inheritance and interface. Here you can access in only within class or child class. <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/ajcotocus\/00e60c92a7a6807d3f9fb649d63e3447.js\"><\/script>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_53257\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_87626\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_53257\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Public Access Modifier:- Public Method or variable can be accessed from anywhere in the class. It means from inside or outside the class and child class also&#8230; <\/p>\n","protected":false},"author":1,"featured_media":10679,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[1720,492,177,5923,5924,5137],"class_list":["post-10606","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-between","tag-difference","tag-php","tag-private","tag-protected","tag-public"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/10606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=10606"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/10606\/revisions"}],"predecessor-version":[{"id":24943,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/10606\/revisions\/24943"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/10679"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=10606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=10606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=10606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}