With End With

php.internals

jason davidson

22 years ago
Ive seen the Control Flow constuct With ...End With used in VB (yup, VB.. :)) although im not a fan of VB, i liked the feature, is there any consideration to this kind of construct for php. here the only example if it i could find online for anyone that hasnt seen it before. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconusingwith.asp Aside from being VB, is there anything wrong with it. Jason

netcat

22 years ago
On Wed, 2003-12-10 at 03:01, jason davidson wrote:
> Ive seen the Control Flow constuct With ...End With used in VB (yup, > VB.. :)) although im not a fan of VB, i liked the feature, is there any > consideration to this kind of construct for php. > here the only example if it i could find online for anyone that hasnt > seen it before. > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconusingwith.asp > Aside from being VB, is there anything wrong with it. > > Jason
As for me - i would solve it with PHP without changing the langauge in the following way:
> Sub MyInput() > With Workbooks("Book1").Worksheets("Sheet1").Cells(1, 1) > .Formula = "=SQRT(50)" > With .Font > .Name = "Arial" > .Bold = True > .Size = 8 > End With > End With > End Sub
would produce somthing like: function my_input() { global $workbooks; $chg=array('formula'=>'sqrt(50)', 'font'=>array('name'=>'Arial','bold'=>true,'size'=>8)): join_properties($workbooks['book1'].workshhets['sheet1'].cells[1][1],$chg) } Here is working(not heavily tested though) example that shows the general idea: <?php header("Content-type: text/plain\n"); $v=array('xxx'=>1,'yyy'=>array('y1'=>7,'y2'=>8)); print_r($v); echo "\n"; function update_props_recursively(&$srcdst,$updater) { foreach($updater as $k=>$v) { if(is_scalar($srcdst[$k])) { $srcdst[$k]=$updater[$k]; } else { update_props_recursively($srcdst[$k],$updater[$k]); } } } $chg=array('xxx'=>2,'yyy'=>array('y2'=>99)); update_props_recursively($v,$chg); print_r($v); ?> -------------------------------------------------------- FREE 10MB email + Antivirus + AntiSpam + POP3 + more.... Get it at http://www.doal.co.il:81/free/?c=both

Alan Knowles

22 years ago
This has been discussed before on the mailing list, (either this or ZE2) and rejected. - have a look through the archives Regards Alan netcat wrote:

Derek Ford

22 years ago
This is highly unusual.... I recently started gathering people who could implement and opinions of those who wanted or didn't want a 'with' construct. http://www.phpfreaks.com/forums/topic11451.php I toyed with the idea, and then when I went into core to implement it, I became _very_ confused and discovered I just wasn't good enough .

jason davidson

22 years ago
Derek Ford wrote:
> This is highly unusual.... I recently started gathering people who > could implement and opinions of those who wanted or didn't want a > 'with' construct. > > http://www.phpfreaks.com/forums/topic11451.php > > I toyed with the idea, and then when I went into core to implement it, > I became _very_ confused and discovered I just wasn't good enough > > > . >
yup, i like the construct, i saw your forum, i would prefer to have some syntax indication that your method or prop call is part of the object block though, which is unlike javascripts implemtation, something like.. with($obj) { .property = ''; .method(); } i know that php already uses the '->' syntax, but as was already posted, that is hideously ugly Jason

Timm Friebe

22 years ago
On Thu, 2003-12-11 at 00:29, Alan Knowles wrote:
> This has been discussed before on the mailing list, (either this or ZE2) > and rejected. - have a look through the archives
http://zend.com/phorum/read.php?num=6&id=242&loc=0&thread=242 - Timm

jason davidson

22 years ago
Timm Friebe wrote:
>On Thu, 2003-12-11 at 00:29, Alan Knowles wrote: > > >>This has been discussed before on the mailing list, (either this or ZE2) >>and rejected. - have a look through the archives >> >> >http://zend.com/phorum/read.php?num=6&id=242&loc=0&thread=242 > >- Timm > > > >
THanks for the thread, i see at least im not the only one that likes the idea, however, i would really prefer the syntax to seperate methods and properties from funcions and vars inside the with block. Jason

T.R. Cox

22 years ago
jason davidson wrote:
> Ive seen the Control Flow constuct With ...End With used in VB (yup, > VB.. :)) although im not a fan of VB, i liked the feature, is there > any consideration to this kind of construct for php. > here the only example if it i could find online for anyone that hasnt > seen it before. > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconusingwith.asp > > Aside from being VB, is there anything wrong with it. > > Jason >
So how would that look in PHP? Something like? With $dbObject; if(->doConnect()==true) { ->doQuery(); while($row = ->fetchArray()) { /* do something with returned row */ } } End With: Just a question from an onlooker. Cheers, BDKR

Walt Boring

22 years ago
BDKR wrote:
> jason davidson wrote: > >> Ive seen the Control Flow constuct With ...End With used in VB (yup, >> VB.. :)) although im not a fan of VB, i liked the feature, is there >> any consideration to this kind of construct for php. >> here the only example if it i could find online for anyone that hasnt >> seen it before. >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconusingwith.asp >> >> Aside from being VB, is there anything wrong with it. >> >> Jason >> > So how would that look in PHP? Something like? > > With $dbObject; > if(->doConnect()==true) > { > ->doQuery(); > while($row = ->fetchArray()) > { /* do something with returned row */ } > } > End With: > > Just a question from an onlooker. > > Cheers, > BDKR >
yuk! This would start php down the slippery slope of unreadable code...et all perlisms. no thanks. Just think of a large block of code and 30 lines down all you had was ->$foo = blah; or ->something('foo') This is high on the yuk meter Yuk ( /) W

T.R. Cox

22 years ago
walt boring wrote:
> BDKR wrote: > >> jason davidson wrote: >> >>> Ive seen the Control Flow constuct With ...End With used in VB (yup, >>> VB.. :)) although im not a fan of VB, i liked the feature, is there >>> any consideration to this kind of construct for php. >>> here the only example if it i could find online for anyone that >>> hasnt seen it before. >>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconusingwith.asp >>> >>> Aside from being VB, is there anything wrong with it. >>> >>> Jason >>> >> So how would that look in PHP? Something like? >> >> With $dbObject; >> if(->doConnect()==true) >> { >> ->doQuery(); >> while($row = ->fetchArray()) >> { /* do something with returned row */ } >> } >> End With: >> >> Just a question from an onlooker. >> >> Cheers, >> BDKR >> > yuk! This would start php down the slippery slope of unreadable > code...et all perlisms. no thanks. > Just think of a large block of code and 30 lines down all you had was > > ->$foo = blah; or ->something('foo')
And we aren't even talking about nested With statements yet! Doh!
> > This is high on the yuk meter
LOL! I agree 100%. I just had to write it out to visualize it. It doesn't visualize very well at all.
> > Yuk > ( /) > > W >
Cheers, BDKR

Justin Hannus

22 years ago
I've used the "with (object)" construct in JavaScript before and I'm assuming it would work the same, but instead of: With $obj ->methodCall(); // ugly ... it would be much sexier like: with ($obj) { methodCall(); } But its all just sugar. As far as implementing it in userland with a recursive function that merges properties, that's way to much unnecessary work. Why not just manually de-reference the object on subsequent method calls? -justin "Bdkr" <bdkr@highsidecafe.com> wrote in message news:3FD762B5.1080908@highsidecafe.com...
> jason davidson wrote: > > > Ive seen the Control Flow constuct With ...End With used in VB (yup, > > VB.. :)) although im not a fan of VB, i liked the feature, is there > > any consideration to this kind of construct for php. > > here the only example if it i could find online for anyone that hasnt > > seen it before. > >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/ vaconusingwith.asp

netcat

22 years ago
On Wed, 2003-12-10 at 22:42, Justin Hannus wrote:
> I've used the "with (object)" construct in JavaScript before and I'm > assuming it would work the same, but instead of: > > With $obj > ->methodCall(); > // ugly ... > > it would be much sexier like: > > with ($obj) { > methodCall(); > } > > But its all just sugar. As far as implementing it in userland with a > recursive function that merges properties, that's way to much unnecessary > work. Why not just manually de-reference the object on subsequent method > calls? > > -justin
I guess your proposal is much simplier (if i understand it correctly) but i personally prefer merging properties becuase of thinking: 1) I have some object 2) I want to change it's prop's 3) So I just "commit" (right word?, "apply" maybe) the changes This way I can have something like that: $styles=array('style1'=> array('font'=>'+2','bold'=>true), 'style2'=> array('font'=>'-1','bold'=>false)); change_props_recursively($mytext,$styles[$cur_style]); Well, having all the changes in a variable and not code gives some advantages i believe... it can be passed, modified, serialized... the applying function can be tweaked maybe ... When the "change" should be computed I still prefer to compute the recursive hash and apply it at once. P.S. Just my 2 agoras. [snip] -------------------------------------------------------- FREE 10MB email + Antivirus + AntiSpam + POP3 + more.... Get it at http://www.doal.co.il:81/free/?c=both