|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Advice:
Always start php code with: <?php and not <? Great example: The PHP Anthology: Object Oriented PHP Solutions <?php class Message { var $message; function Message() {} function setMessage($message) { $this->message = $message; } function getMessage() { return $this->message; } } class PoliteMessage extends Message { function PoliteMessage() { $this->setMessage('How are you today?'); } } class TerseMessage extends Message { function TerseMessage() { $this->setMessage('Howzit?'); } } class RudeMessage extends Message { function RudeMessage() { $this->setMessage('You look like *%&* today!'); } } class MessageReader { var $messages; function MessageReader(& $messages) { $this->messages = & $messages; $this->readMessages(); } function readMessages() { foreach ( $this->messages as $message ) { echo ( $message->getMessage().' ' ); } } } $classNames = array ('PoliteMessage','TerseMessage','RudeMessage'); srand ((float)microtime()*1000000); shuffle ($classNames); $messages = array(); for ( $i = 0; $i < 10; $i++ ) { shuffle($classNames); $messages[] = new $classNames[0](); } $messageReader = new MessageReader($messages); ?> Note the following: Blue code: $classNames = Array of message objects that are children of (extends) the parent class Message. Red code: The MerssageReader class takes an array of message objects in its constructor. This is effective code. May be the same technique can be used on an email parser. |
|
||||
|
But does it not make the code less portable?
|
|
||||
|
This option is turned on by default in php.ini via short_open_tag = 1 so unless someone has manually changed it in thier ini file it presents no problem as this is the case back to PHP 3.0. Again, thanks for the advice though....
|
|
||||
|
I know.
Problem: The short tag style causes problem in a document where PHP is mixed with XML. Example: <?xml will mistake an XML instruction with a PHP opening tag. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |