note 99153 added to splenum.construct

From: Date: Fri, 30 Jul 2010 16:11:37 +0000
Subject: note 99153 added to splenum.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-171236@lists.php.net to get a copy of this message
Here's a clearer example usage in case anyone else finds the current documentation confusing (as I did). <?php class Fruit extends SplEnum { // If no value is given during object construction this value is used const __default = 1; // Our enum values const APPLE = 1; const ORANGE = 2; } $myApple = new Fruit(); $myOrange = new Fruit(Fruit::ORANGE); $fail = 1; function eat(Fruit $aFruit) { if (Fruit::APPLE == $aFruit) { echo "Eating an apple.\n"; } elseif (Fruit::ORANGE == $aFruit) { echo "Eating an orange.\n"; } } eat($myApple); // Eating an apple. eat($myOrange); // Eating an orange. eat($fail); // PHP Catchable fatal error: Argument 1 passed to eat() must be an instance of Fruit, integer given ?> ---- Server IP: 69.147.83.197 Probable Submitter: 71.230.4.167 ---- Manual Page -- http://www.php.net/manual/en/splenum.construct.php Edit -- https://master.php.net/note/edit/99153 Del: integrated -- https://master.php.net/note/delete/99153/integrated Del: useless -- https://master.php.net/note/delete/99153/useless Del: bad code -- https://master.php.net/note/delete/99153/bad+code Del: spam -- https://master.php.net/note/delete/99153/spam Del: non-english -- https://master.php.net/note/delete/99153/non-english Del: in docs -- https://master.php.net/note/delete/99153/in+docs Del: other reasons-- https://master.php.net/note/delete/99153 Reject -- https://master.php.net/note/reject/99153 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171236) next »