FredAt Posted December 6, 2009 Share Posted December 6, 2009 Is there a PHP way to do the equivalent of the following Delphi snippet with someObject do begin x:=objPropA;//some stuff with objPropA end; Apart from reducing the verbosity of code it also reduces the possibility of typo errors. The best I have managed is to convert the object to an array and then refer to the associative elements in the array. This works for me because I ensure that I am only handling simple PHP objects - i.e. ones which do not have objects as properties in turn. However, given just how neat PHP is I am sure that there is a better way. I'd appreciate any pointers. Link to comment https://forums.phpfreaks.com/topic/184155-php-equivalent-of-delphi-with/ Share on other sites More sharing options...
Mchl Posted December 6, 2009 Share Posted December 6, 2009 There's no such syntax in PHP. Link to comment https://forums.phpfreaks.com/topic/184155-php-equivalent-of-delphi-with/#findComment-972357 Share on other sites More sharing options...
trq Posted December 7, 2009 Share Posted December 7, 2009 If your objects method's return $this you can use a similar syntax called 'method chaining'. $obj = new foo; $obj->method1() ->method2() ->method3() ->method4() ->method5(); its probably the closest you'll get and of course is not always available (depending on your methods). Link to comment https://forums.phpfreaks.com/topic/184155-php-equivalent-of-delphi-with/#findComment-972606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.