Ok, I have seen many different examples of OOP, but nothing quite like this.
Someone was showing me syntax for Ruby the other day, and it got me thinking, wouldn't it be neat to imitate ruby, or be it a little more generic, dot notation for OOP ways of calling methods like Java, javascript, ruby and others. So I came up with this.
Seems to work in PHP5, but chokes in PHP4. I would like input on this setup for calling methods. <plaintext><?php class myString { private $value = ''; function __construct() { } function in($str=null) { if ( is_null($str) ) { echo "A string wasn't given."; exit; } $this->value = $str; $this->setProperties(); return $this; } function out() { echo $this->value; } function get() { return $this->value; } function append($a) { $this->value = $this->value.$a; $this->setProperties(); return $this; } function prepend($a) { $this->value = $a.$this->value; $this->setProperties(); return $this; } function regex_replace($from, $to) { $this->value = preg_replace("!{$from}!", $to, $this->value); $this->setProperties(); return $this; } function setProperties() { $this->str_length = strlen($this->value); return $this; } function length() { return $this->str_length; } } $str = new myString; echo $str->in("Starting String!")->prepend("Second String!")->regex_replace(' ', '_')->get(); echo $str->length(); $str->in("A new string")->out(); ?> Has anybody else seen this style of syntax? Have they used this style of syntax? If so, what is your opinion of this style? TIA Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php