Jump to content

PHP equivalent of Delphi with


FredAt

Recommended Posts

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

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.