gr4devel Posted August 30, 2013 Share Posted August 30, 2013 (edited) Hi community . A very general question. What is your personal preference concerning the use of only one return statement per function. In the past I've been used to this coding style but now I really appreciate the brevity that multiple return statement in a function (or object method) grant me when writing code and as a result I used it a lot when writing my modules. Now I'm particularly worried about going against the coding standards suggested by PS. How about you guys? P.S: if the post isn't placed in the right position in the forum or if the topic isn't right for the forum itself please forgive me and notify me so that I can remove it Edited August 30, 2013 by gr4devel (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 30, 2013 Share Posted August 30, 2013 as far as i know - in PHP there is no way to return 2 or more variables. you can return an array of variables (but it is still one variable) for example return array($var1,$var2,$var3); Link to comment Share on other sites More sharing options...
gr4devel Posted August 30, 2013 Author Share Posted August 30, 2013 (edited) mmm...wait I think I didn't explain myself. I don't mean to return multiple values but to use multiple return statement in different positions in a given function or method. e.g: function A ($a) { if($a) return 'hi'; return 'bye'; } Sorry for the lack of my precision. Edited August 30, 2013 by gr4devel (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted August 30, 2013 Share Posted August 30, 2013 for me - everything is fine in this code. Im using these statements. I don't know why you think that you're going against the coding standards suggested by PS in my opinion if your code is compatible with php - you definitely don't have to worry Link to comment Share on other sites More sharing options...
gr4devel Posted August 30, 2013 Author Share Posted August 30, 2013 (edited) Nice to know my friend . I was worried about the "We recommend one return per method/function." that I've found reading the coding standards (http://doc.prestashop.com/display/PS15/Coding+Standards#CodingStandards-Returnvalues). However let me thank you as always for the participation to this topi Edited August 30, 2013 by gr4devel (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts