Show() function"; } } class ...">

Procedure for Echo Statements

Here is my code:

<?php class Test_Class { public function Show() { return "Test_Class->Show() function"; } } class Test_Class2 { public function Show() { echo "Test_Class2->Show() function"; } } $var1 = new Test_Class(); $var2 = new Test_Class2(); echo "var1 :: " . $var1->Show() . "<br />"; echo "var2 :: " . $var2->Show() . "<br />"; ?> 

Here's the conclusion:

  var1 :: Test_Class->Show() function Test_Class2->Show() functionvar2 :: 

You will notice that the class in which the string returns has a result that will look where it used to be, while the class in which echo has the result appears before the echo that it is called.

Now I know that it is processed first, and why it appears first. But how does it look at a lower level?

This is something like: .. parse
.. parse
.... Hi! And an echo statement, let's parse it!
...... Hi! inside this echo operator that we are playing out is an object method, let's analyze what now
........ There is an echo inside this method, so give an estimate (output of the internal echo)
.... We have finished evaluating the expression echo (output of an external external echo)
.. parse
.. parse

It's close?

Does anyone know the "order of operations" when it comes to this?

+4
source share
3 answers

This has nothing to do with parsing.

echo needs an argument; it cannot be called until this argument is known. In the second example, this argument is formed from two concatenation operations. These operations must be performed before the argument is known. Therefore, you must first evaluate the arguments of these concatenation operations. Thus, $var2->Show() is evaluated before any concatenation is performed.

+4
source

A string is concatenated at run time. The string must be built before echo'd appears.

If you want the parts to be displayed from left to right, use commas:

 echo "var1 :: ", $var1->Show() , "<br />"; echo "var2 :: " , $var2->Show() , "<br />"; /* output: var1 :: Test_Class->Show() function var2 :: Test_Class2->Show() function */ 
+5
source

Your order is pretty much right. Everything on the right side of echo must be evaluated before the actual echo function is called. This means that every echo called from functions that will call your arguments will be output first.

+3
source

Source: https://habr.com/ru/post/1398695/


All Articles