How to complete the program to display & ldquo; A private static variable & rdquo; without instantiating the class

advertisements

Complete the program to display "A private static variable" without instantiating the class:

 <?php
    /*
        Complétez le programme pour qu'il affiche 

        "Une variable privée statique"

        sans instancier la classe
    */

    /*
        Complete the program to display

        "A private static variable"

        without instantiating the class
    */

        class Une_classe {
            private static $variable = "Une variable privée statique";

            public static function afficher_variable() {

            }
        }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <?php
        // imprimez la variable $variable sans instancier la classe
        // Print the variable $ variable without instantiating the class
    ?>
    </body>
    </html>


May be I'm wrong or may be I can't understand the question, but in case the function or variable is deffined as static, it cen be directly accessed by classname::function/$variable. In this way the next has to be working because I'm calling the public static function, which types private static variable. Really I've no tried, because I can't right now but it has to work. sans instancier la classe */

/*
    Complete the program to display

    "A private static variable"

    without instantiating the class
*/

    class Une_classe {
        private static $variable = "Une variable privée statique";

        public static function afficher_variable() {
            echo Une_classe::$variable;
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
    // imprimez la variable $variable sans instancier la classe
    // Print the variable $ variable without instantiating the class
    Une_classe::afficher_variable();
?>
</body>
</html>