Hướng dẫn php echo multiple lines
I am having a hard time where this code
is overlapping the column in a
asked Sep 9, 2016 at 13:00
10 You can wrap your string using
This function will wrap your long string into multiline. Or You can use this css for
your
answered Sep 9, 2016 at 13:06
Neel IonNeel Ion 1,5471 gold badge11 silver badges14 bronze badges 12 try this it's work
answered Sep 9, 2016 at 13:07
4 In CSS :
answered Sep 9, 2016 at 13:32
1 Not the answer you're looking for? Browse other questions tagged php html or ask your own question.How do you write PHP Arrow function with multiple line expressions? JavaScript One Line Example:
PHP One Line Equivalent:
Javascript Multiple Line Example:
WHAT IS PHP Equivalent for multiple line???? asked Jan 26, 2021 at 15:06 Emeka MbahEmeka Mbah 15.6k8 gold badges70 silver badges93 bronze badges 3 Arrow functions in PHP have the form You can write the expression over multiple lines without problem:
If you really need multiple expressions, then you can simply use anonymous function. The closures aren't automatic as they are with arrow functions, but if you don't need it, it gives exactly the same result.
answered Jan 26, 2021 at 15:13 BlackholeBlackhole 19.5k7 gold badges67 silver badges67 bronze badges 4 The usage of multiple expressions is not allowed, according to the RFC. It covers the assignment of only a single expression. The extension is discussed further down in the RFC, but not implemented answered Jan 26, 2021 at 15:13 Nico HaaseNico Haase 9,85735 gold badges37 silver badges60 bronze badges Not the answer you're looking for? Browse other questions tagged php arrow-functions or ask your own question.Hi Nuno,
Welcome to the list. Firstly, it's probably worth having a look in the Secondly, I'd like to point out that "short closures" actually have
I think it's worth making clear which of those three features we are Feature 1 doesn't extend to code blocks in an obvious way. In some Feature 2 is probably the one most people actually want extended, but in There are currently very few places in PHP where the scope of a
variable In a single-expression closure, as currently allowed, there is
limited If you want to capture variables $a, $b, and $c, but have local $f = function() use ($a, $b, $c) { If we added an opt-in syntax for "capture everything", we might instead $f = function() use (*) { Without re-initialising all local variables, we would no longer be able One use case I've seen proposed is closures which capture a large number In the above example I deliberately did not use the "fn()=>" syntax, I would personally prefer the "fn()=>" syntax to carry on meaning "this Regards, -- unread
Good analysis. I agree #2 is the strongest motivator for some kind of improvement / change. In at least one prior language I have used there was no distinction between local scope inside and outside of a closure, so when I first realized I had to use the "use" clause to make variable visible it was surprising to me. In PHP I find this requirement rather annoying in the majority of cases. My functions and closures tend to be short and the number of local variables I use — both inside and outside the closure —tend to be small so I don't have a problem with confusing scope. Having to explicitly name the variables in a use statement feels like unfortunate overkill. But I do get your point. OTOH, when inherited local variables are NOT modified within the closure, does that actually cause a problem? (honest question) If not — and please check my logic — I would suggest PHP 8.1+ could allow closures to IMPLICITLY inherit local variables, but ONLY for variables that are READ, not for variables that are written. Given this approach, variables would still need to be declared when variables need to be written, e.g. "use ( &$foo )" Although this relaxing of requirement to declare variables could theoretically break existing code, only code where variables are read inside closures before they are assigned with the same name as variables assigned outside the closure would "break", and those cases are flagged as a warning when error reporting is on. For me, that would probably cover 90%+ of the use cases my the requirement to employ the "use" statement feels like overkill. -Mike unread
Something like "use (*)" seems like a great enhancement to me. I often
In these cases there is a lot of redundancy because of having to
import
This would also increase code readability. unread Yes, "use (*)" is perfect! With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem, Michael Voříšek
unread On Mon, Oct 5, 2020 at 12:00 PM Michael Voříšek - ČVUT FEL <
How should php deal with the scenario where you want to
unread
The easiest would be to only allow "use ()" with no references or unread
FTR, short arrow function implicitly only support "by value" bindings, I I do use by ref with closures btw.
unread
I would take a page out of C++'s book here. In C++ a closure is (some of [capture, vars](type argName) -> returnType { Looking specifically at the capture vars section (in the
example we are [=](bool bval) -> void {} The equal sign (as above) captures all variables used in the closure by Exceptions can be added to that list just as you suggested, so: [=,&foo](double dval) -> double { return foo + dval; } Or &,foo -> void { doSomething(foo); } I think we could apply the same in PHP terms: function(float $dval) use ($, &$foo) { return $foo + $dval; }; Plus or minor for parser convenience. -Sara unread To me that seems like a great argument in favour of the proposal. If you'll
-- unread
Not necessarily: the arrow functions were specifically
implemented for I like the "function () use (*)" suggestion because it is explicit and unread Hi internals The reason multi-line short closures are so valued by userland devs is because they are shorter to write and prettier to read. While some of us might not agree on the definition of "prettier to read", it was one of the key arguments for adding short closures in the first place:
We can have the discussion again on whether we like short closures or not, but it turned out most of internals and userland devs do — based on the vote count in the sigle line RFC and the reaction on Nuno's PR, as well as my experience from an OSS maintainer point of view. Furthermore, the I also want to quote from Larry Garfields book on thinking functionally in PHP [2], to demonstrate the signicant impact short closures already had today:
Larry continues to write a whole book about functional programming in PHP, and short closures play a significant role. So I hope to see more input on Nuno's PR from a techinical point of view: what's missing, what's needed to get this to the RFC phase, … and not only discussions about what syntax we like or not, or whether there are other ways to solve the same problem. Please provide Nuno with actionable feedback. Kind regards [1] https://wiki.php.net/rfc/arrow_functions_v2 https://wiki.php.net/rfc/arrow_functions_v2
unread First, can you please bottom-post and not top-post.
I didn't know we were meant to do code golfing with production code, might
If it's not about being able to use
all variables (or even just one that is
Wanting something isn't an argument. Looking at what part of the
community named arguments, property promotions, short closures, … these are all
Obviously nothing is necessary, we could write assembler style with only I also want to quote from Larry Garfields book on thinking functionally in
Finally a resemblance of an actual argument.
Jokes aside, the actionable feedback is to argue why
auto capture of the Going back to the Moreover, Larry has also made a PR which extends short closures [2] in a Regards George P. Banyard [1] https://youtu.be/Qa_xVjTiOUw?t=1895 unread
Ressending to the list as I seem to have messed up my reply. unread Hi Brent,
I don't know how much of the earlier discussion you saw at the time, or That doesn't mean we can't discuss multi-statement arrow functions now -
Rather than "missing the point", I think it's a case of different people (a) an improved syntax for declaring closures (in the way that [$foo, Those who wanted (c) are generally happy with what we have, with perhaps Those who wanted (b) generally see the arrow syntax as a means to an Those who wanted (a) may see things the other way around: the short There's probably no way to please all three groups (and the various I look forward to seeing the RFC if Nuno decides to proceed with it, [1] https://externals.io/message/98045#98209 Regards, -- |