⊗ppOpStPr 46 of 107 menu

Static Properties in OOP in PHP

In addition to static methods, you can also create static properties. Such properties are also declared using the keyword static:

<?php class Test { public static $property; } ?>

You can write something to a static property and read from it. The property name is specified with the dollar sign:

<?php Test::$property = 'test'; echo Test::$property; // outputs 'test' ?>

Create a Num class that will have two public static properties: num1 and num2. Write the number 2 to the first property, and the number 3 to the second one. Display the sum of the property values on the screen.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline