[{"data":1,"prerenderedAt":656},["ShallowReactive",2],{"content-\u002Fphp\u002Fpatterns\u002Fsingleton":3,"related-\u002Fphp\u002Fpatterns\u002Fsingleton":531,"sidebar-content":635},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"tags":10,"date":13,"body":14,"_type":525,"_id":526,"_source":527,"_file":528,"_stem":529,"_extension":530},"\u002Fphp\u002Fpatterns\u002Fsingleton","patterns",false,"","Singleton Pattern","Implementing the singleton pattern in PHP",[11,5,12],"php","backend","2026-03-13",{"type":15,"children":16,"toc":522},"root",[17,25,31,516],{"type":18,"tag":19,"props":20,"children":22},"element","h2",{"id":21},"singleton-pattern",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":24,"value":30},"The singleton pattern ensures a class has only one instance.",{"type":18,"tag":32,"props":33,"children":36},"pre",{"className":34,"code":35,"language":11,"meta":7,"style":7},"language-php shiki shiki-themes github-light github-dark","class Database\n{\n    private static ?self $instance = null;\n\n    private function __construct(\n        private readonly PDO $pdo\n    ) {}\n\n    public static function getInstance(): self\n    {\n        if (self::$instance === null) {\n            self::$instance = new self(\n                new PDO('mysql:host=localhost;dbname=app', 'root', '')\n            );\n        }\n        return self::$instance;\n    }\n\n    public function query(string $sql): array\n    {\n        return $this->pdo->query($sql)->fetchAll();\n    }\n}\n",[37],{"type":18,"tag":38,"props":39,"children":40},"code",{"__ignoreMap":7},[41,59,69,109,119,142,166,175,183,220,229,267,298,346,355,364,383,392,400,440,448,499,507],{"type":18,"tag":42,"props":43,"children":46},"span",{"class":44,"line":45},"line",1,[47,53],{"type":18,"tag":42,"props":48,"children":50},{"style":49},"--shiki-default:#D73A49;--shiki-dark:#F97583",[51],{"type":24,"value":52},"class",{"type":18,"tag":42,"props":54,"children":56},{"style":55},"--shiki-default:#6F42C1;--shiki-dark:#B392F0",[57],{"type":24,"value":58}," Database\n",{"type":18,"tag":42,"props":60,"children":62},{"class":44,"line":61},2,[63],{"type":18,"tag":42,"props":64,"children":66},{"style":65},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[67],{"type":24,"value":68},"{\n",{"type":18,"tag":42,"props":70,"children":72},{"class":44,"line":71},3,[73,78,83,88,93,98,104],{"type":18,"tag":42,"props":74,"children":75},{"style":49},[76],{"type":24,"value":77},"    private",{"type":18,"tag":42,"props":79,"children":80},{"style":49},[81],{"type":24,"value":82}," static",{"type":18,"tag":42,"props":84,"children":85},{"style":49},[86],{"type":24,"value":87}," ?self",{"type":18,"tag":42,"props":89,"children":90},{"style":65},[91],{"type":24,"value":92}," $instance ",{"type":18,"tag":42,"props":94,"children":95},{"style":49},[96],{"type":24,"value":97},"=",{"type":18,"tag":42,"props":99,"children":101},{"style":100},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[102],{"type":24,"value":103}," null",{"type":18,"tag":42,"props":105,"children":106},{"style":65},[107],{"type":24,"value":108},";\n",{"type":18,"tag":42,"props":110,"children":112},{"class":44,"line":111},4,[113],{"type":18,"tag":42,"props":114,"children":116},{"emptyLinePlaceholder":115},true,[117],{"type":24,"value":118},"\n",{"type":18,"tag":42,"props":120,"children":122},{"class":44,"line":121},5,[123,127,132,137],{"type":18,"tag":42,"props":124,"children":125},{"style":49},[126],{"type":24,"value":77},{"type":18,"tag":42,"props":128,"children":129},{"style":49},[130],{"type":24,"value":131}," function",{"type":18,"tag":42,"props":133,"children":134},{"style":100},[135],{"type":24,"value":136}," __construct",{"type":18,"tag":42,"props":138,"children":139},{"style":65},[140],{"type":24,"value":141},"(\n",{"type":18,"tag":42,"props":143,"children":145},{"class":44,"line":144},6,[146,151,156,161],{"type":18,"tag":42,"props":147,"children":148},{"style":49},[149],{"type":24,"value":150},"        private",{"type":18,"tag":42,"props":152,"children":153},{"style":49},[154],{"type":24,"value":155}," readonly",{"type":18,"tag":42,"props":157,"children":158},{"style":100},[159],{"type":24,"value":160}," PDO",{"type":18,"tag":42,"props":162,"children":163},{"style":65},[164],{"type":24,"value":165}," $pdo\n",{"type":18,"tag":42,"props":167,"children":169},{"class":44,"line":168},7,[170],{"type":18,"tag":42,"props":171,"children":172},{"style":65},[173],{"type":24,"value":174},"    ) {}\n",{"type":18,"tag":42,"props":176,"children":178},{"class":44,"line":177},8,[179],{"type":18,"tag":42,"props":180,"children":181},{"emptyLinePlaceholder":115},[182],{"type":24,"value":118},{"type":18,"tag":42,"props":184,"children":186},{"class":44,"line":185},9,[187,192,196,200,205,210,215],{"type":18,"tag":42,"props":188,"children":189},{"style":49},[190],{"type":24,"value":191},"    public",{"type":18,"tag":42,"props":193,"children":194},{"style":49},[195],{"type":24,"value":82},{"type":18,"tag":42,"props":197,"children":198},{"style":49},[199],{"type":24,"value":131},{"type":18,"tag":42,"props":201,"children":202},{"style":55},[203],{"type":24,"value":204}," getInstance",{"type":18,"tag":42,"props":206,"children":207},{"style":65},[208],{"type":24,"value":209},"()",{"type":18,"tag":42,"props":211,"children":212},{"style":49},[213],{"type":24,"value":214},":",{"type":18,"tag":42,"props":216,"children":217},{"style":49},[218],{"type":24,"value":219}," self\n",{"type":18,"tag":42,"props":221,"children":223},{"class":44,"line":222},10,[224],{"type":18,"tag":42,"props":225,"children":226},{"style":65},[227],{"type":24,"value":228},"    {\n",{"type":18,"tag":42,"props":230,"children":232},{"class":44,"line":231},11,[233,238,243,248,253,258,262],{"type":18,"tag":42,"props":234,"children":235},{"style":49},[236],{"type":24,"value":237},"        if",{"type":18,"tag":42,"props":239,"children":240},{"style":65},[241],{"type":24,"value":242}," (",{"type":18,"tag":42,"props":244,"children":245},{"style":49},[246],{"type":24,"value":247},"self::",{"type":18,"tag":42,"props":249,"children":250},{"style":65},[251],{"type":24,"value":252},"$instance ",{"type":18,"tag":42,"props":254,"children":255},{"style":49},[256],{"type":24,"value":257},"===",{"type":18,"tag":42,"props":259,"children":260},{"style":100},[261],{"type":24,"value":103},{"type":18,"tag":42,"props":263,"children":264},{"style":65},[265],{"type":24,"value":266},") {\n",{"type":18,"tag":42,"props":268,"children":270},{"class":44,"line":269},12,[271,276,280,284,289,294],{"type":18,"tag":42,"props":272,"children":273},{"style":49},[274],{"type":24,"value":275},"            self::",{"type":18,"tag":42,"props":277,"children":278},{"style":65},[279],{"type":24,"value":252},{"type":18,"tag":42,"props":281,"children":282},{"style":49},[283],{"type":24,"value":97},{"type":18,"tag":42,"props":285,"children":286},{"style":49},[287],{"type":24,"value":288}," new",{"type":18,"tag":42,"props":290,"children":291},{"style":49},[292],{"type":24,"value":293}," self",{"type":18,"tag":42,"props":295,"children":296},{"style":65},[297],{"type":24,"value":141},{"type":18,"tag":42,"props":299,"children":301},{"class":44,"line":300},13,[302,307,311,316,322,327,332,336,341],{"type":18,"tag":42,"props":303,"children":304},{"style":49},[305],{"type":24,"value":306},"                new",{"type":18,"tag":42,"props":308,"children":309},{"style":100},[310],{"type":24,"value":160},{"type":18,"tag":42,"props":312,"children":313},{"style":65},[314],{"type":24,"value":315},"(",{"type":18,"tag":42,"props":317,"children":319},{"style":318},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[320],{"type":24,"value":321},"'mysql:host=localhost;dbname=app'",{"type":18,"tag":42,"props":323,"children":324},{"style":65},[325],{"type":24,"value":326},", ",{"type":18,"tag":42,"props":328,"children":329},{"style":318},[330],{"type":24,"value":331},"'root'",{"type":18,"tag":42,"props":333,"children":334},{"style":65},[335],{"type":24,"value":326},{"type":18,"tag":42,"props":337,"children":338},{"style":318},[339],{"type":24,"value":340},"''",{"type":18,"tag":42,"props":342,"children":343},{"style":65},[344],{"type":24,"value":345},")\n",{"type":18,"tag":42,"props":347,"children":349},{"class":44,"line":348},14,[350],{"type":18,"tag":42,"props":351,"children":352},{"style":65},[353],{"type":24,"value":354},"            );\n",{"type":18,"tag":42,"props":356,"children":358},{"class":44,"line":357},15,[359],{"type":18,"tag":42,"props":360,"children":361},{"style":65},[362],{"type":24,"value":363},"        }\n",{"type":18,"tag":42,"props":365,"children":367},{"class":44,"line":366},16,[368,373,378],{"type":18,"tag":42,"props":369,"children":370},{"style":49},[371],{"type":24,"value":372},"        return",{"type":18,"tag":42,"props":374,"children":375},{"style":49},[376],{"type":24,"value":377}," self::",{"type":18,"tag":42,"props":379,"children":380},{"style":65},[381],{"type":24,"value":382},"$instance;\n",{"type":18,"tag":42,"props":384,"children":386},{"class":44,"line":385},17,[387],{"type":18,"tag":42,"props":388,"children":389},{"style":65},[390],{"type":24,"value":391},"    }\n",{"type":18,"tag":42,"props":393,"children":395},{"class":44,"line":394},18,[396],{"type":18,"tag":42,"props":397,"children":398},{"emptyLinePlaceholder":115},[399],{"type":24,"value":118},{"type":18,"tag":42,"props":401,"children":403},{"class":44,"line":402},19,[404,408,412,417,421,426,431,435],{"type":18,"tag":42,"props":405,"children":406},{"style":49},[407],{"type":24,"value":191},{"type":18,"tag":42,"props":409,"children":410},{"style":49},[411],{"type":24,"value":131},{"type":18,"tag":42,"props":413,"children":414},{"style":55},[415],{"type":24,"value":416}," query",{"type":18,"tag":42,"props":418,"children":419},{"style":65},[420],{"type":24,"value":315},{"type":18,"tag":42,"props":422,"children":423},{"style":49},[424],{"type":24,"value":425},"string",{"type":18,"tag":42,"props":427,"children":428},{"style":65},[429],{"type":24,"value":430}," $sql)",{"type":18,"tag":42,"props":432,"children":433},{"style":49},[434],{"type":24,"value":214},{"type":18,"tag":42,"props":436,"children":437},{"style":49},[438],{"type":24,"value":439}," array\n",{"type":18,"tag":42,"props":441,"children":443},{"class":44,"line":442},20,[444],{"type":18,"tag":42,"props":445,"children":446},{"style":65},[447],{"type":24,"value":228},{"type":18,"tag":42,"props":449,"children":451},{"class":44,"line":450},21,[452,456,461,466,471,475,480,485,489,494],{"type":18,"tag":42,"props":453,"children":454},{"style":49},[455],{"type":24,"value":372},{"type":18,"tag":42,"props":457,"children":458},{"style":100},[459],{"type":24,"value":460}," $this",{"type":18,"tag":42,"props":462,"children":463},{"style":49},[464],{"type":24,"value":465},"->",{"type":18,"tag":42,"props":467,"children":468},{"style":65},[469],{"type":24,"value":470},"pdo",{"type":18,"tag":42,"props":472,"children":473},{"style":49},[474],{"type":24,"value":465},{"type":18,"tag":42,"props":476,"children":477},{"style":55},[478],{"type":24,"value":479},"query",{"type":18,"tag":42,"props":481,"children":482},{"style":65},[483],{"type":24,"value":484},"($sql)",{"type":18,"tag":42,"props":486,"children":487},{"style":49},[488],{"type":24,"value":465},{"type":18,"tag":42,"props":490,"children":491},{"style":55},[492],{"type":24,"value":493},"fetchAll",{"type":18,"tag":42,"props":495,"children":496},{"style":65},[497],{"type":24,"value":498},"();\n",{"type":18,"tag":42,"props":500,"children":502},{"class":44,"line":501},22,[503],{"type":18,"tag":42,"props":504,"children":505},{"style":65},[506],{"type":24,"value":391},{"type":18,"tag":42,"props":508,"children":510},{"class":44,"line":509},23,[511],{"type":18,"tag":42,"props":512,"children":513},{"style":65},[514],{"type":24,"value":515},"}\n",{"type":18,"tag":517,"props":518,"children":519},"style",{},[520],{"type":24,"value":521},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":71,"depth":71,"links":523},[524],{"id":21,"depth":61,"text":8},"markdown","content:php:patterns:singleton.md","content","php\u002Fpatterns\u002Fsingleton.md","php\u002Fpatterns\u002Fsingleton","md",[532,540,545,551,556,561,566,571,576,585,591,596,601,606,611,616,624,629],{"_path":533,"title":534,"description":535,"tags":536,"date":539},"\u002Fcompetitive-programming\u002Farray-manipulation\u002Ffor-looping","For Looping in Python","Using for loops to manipulate arrays in Python.",[537,12,538],"python","arrays","2026-03-18",{"_path":541,"title":542,"description":543,"tags":544,"date":539},"\u002Fcompetitive-programming\u002Farray-manipulation\u002Fwhile-looping","While Looping in Python","Using while loops to manipulate arrays in Python.",[537,12,538],{"_path":546,"title":547,"description":548,"tags":549,"date":550},"\u002Fcompetitive-programming\u002Fassignments","Assignments","Assignments in Python for competitive programming.",[537,12],"2026-04-10",{"_path":552,"title":553,"description":554,"tags":555,"date":550},"\u002Fcompetitive-programming\u002Fdata-type","Data Types","Data types in Python for competitive programming.",[537,12],{"_path":557,"title":558,"description":559,"tags":560,"date":550},"\u002Fcompetitive-programming\u002Fhash-map","Hash Map","Hash map implementation in Python for competitive programming.",[537,12],{"_path":562,"title":563,"description":564,"tags":565,"date":550},"\u002Fcompetitive-programming\u002Finput-output","Input and Output","Handling input and output in Python for competitive programming.",[537,12],{"_path":567,"title":568,"description":569,"tags":570,"date":539},"\u002Fcompetitive-programming\u002Fmath-library\u002Fsum","Sum Elements","Using for loops to sum elements in Python.",[537,12,538],{"_path":572,"title":573,"description":574,"tags":575,"date":539},"\u002Fcompetitive-programming\u002Fmath-library\u002Fsummary","Summary","Summary of the math library in Python.",[537,12,538],{"_path":577,"title":578,"description":579,"tags":580,"date":584},"\u002Fdocker\u002Fcheat-sheets","Docker Cheat Sheets","Cheat sheets for frequently used Docker commands and concepts",[581,582,583],"docker","devops","infrastructure","2026-05-01",{"_path":586,"title":587,"description":588,"tags":589,"date":590},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-container","Docker Container","Introduction to Docker containers and their usage",[581,582,583],"2026-03-12",{"_path":592,"title":593,"description":594,"tags":595,"date":590},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-execution","Docker Execution","Introduction to Docker execution and their usage",[581,582,583],{"_path":597,"title":598,"description":599,"tags":600,"date":590},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-image","Docker Image","Introduction to Docker images and their usage",[581,582,583],{"_path":602,"title":603,"description":604,"tags":605,"date":590},"\u002Fdocker\u002Fdocker-dasar\u002Fdocker-logging","Docker Logging","Introduction to Docker logging and their usage",[581,582,583],{"_path":607,"title":608,"description":609,"tags":610,"date":590},"\u002Fdocker\u002Fdocker-prerequisites\u002Fdocker-installation","Docker Installation","Introduction to Docker installation and their usage",[581,582,583],{"_path":612,"title":613,"description":614,"tags":615,"date":590},"\u002Fdocker\u002Fresources","Docker Resources","Collection of Docker resources for learning and reference",[581,582,583],{"_path":617,"title":618,"description":619,"tags":620,"date":590},"\u002Fjavascript\u002Fpromises","Promise Patterns","Common JavaScript promise patterns and async\u002Fawait usage",[621,622,623],"javascript","frontend","async",{"_path":625,"title":626,"description":627,"tags":628,"date":539},"\u002Fphp\u002Farrays","PHP Array Functions","Essential PHP array functions and patterns",[11,12,538],{"_path":630,"title":631,"description":632,"tags":633,"date":634},"\u002Fphp\u002Freferences","PHP References (&)","Useful PHP reference snippets and patterns",[11,12],"2026-03-19",[636,637,638,639,640,641,642,643,644,646,647,648,649,650,651,652,653,654,655],{"_path":533,"title":534,"weight":222},{"_path":541,"title":542,"weight":222},{"_path":546,"title":547,"weight":71},{"_path":552,"title":553,"weight":61},{"_path":557,"title":558,"weight":222},{"_path":562,"title":563,"weight":45},{"_path":567,"title":568,"weight":442},{"_path":572,"title":573,"weight":222},{"_path":577,"title":578,"weight":645},100,{"_path":586,"title":587,"weight":442},{"_path":592,"title":593,"weight":501},{"_path":597,"title":598,"weight":450},{"_path":602,"title":603,"weight":509},{"_path":607,"title":608,"weight":222},{"_path":612,"title":613,"weight":45},{"_path":617,"title":618},{"_path":625,"title":626,"weight":45},{"_path":4,"title":8},{"_path":630,"title":631,"weight":61},1777665108304]