There is a certain operator ->, which allows the use of methods of a particular class. The php file contains approximately the following code:

<?php // Π—Π΄Π΅ΡΡŒ ΠΈΠ΄Ρ‘Ρ‚ инициализация Π‘Π” ?> <table> <thead> <tr> <th>Π¨Π°ΠΏΠΊΠ°1</th> <th>Π¨Π°ΠΏΠΊΠ°2</th> </tr> </thead> <tbody> <?php $foo = Class->method; // Π—Π΄Π΅ΡΡŒ ΠΈΠ΄Ρ‘Ρ‚ присвоСниС Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹ ΠΈΠ· Π±Π΄ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ $foo, ΠΏΡ€ΠΈΡ‡Π΅ΠΌ Ρ‚Π°Π±Π»ΠΈΡ†Π° пСрСдаСтся ΠΊΠ°ΠΊ массив foreach($foo as $element){ $head1 = $element['head1']; $head2 = $element['head2']; echo "<tr><td>".$head1; echo "</td><td>".$head2; echo "</td></tr>"; } ?> </tbody> </table> 

The conclusion of this is the following:

 method; foreach($foo as $element){ $head1 = $element['head1']; $head2 = $element['head2']; echo ""; } ?> 

And then the table is drawn, with a header, as it should, and the contents are two cells on one line, the contents of the first:

 ".$head1; echo " 

... and the second:

 ".$head2; echo " 

As far as I understand, the point is in the operator ->, which is used in html for commenting, and in php to call the class methods. How to fix this?

And, and if someone has a desire to advise me to make a request through ajax to retrieve the contents of the table: it does not knock, I need this way.

  • How? Give an example, please - Semior
  • What do you have in $element['head1'] and $element['head2'] ? - Bookin
  • The most common line - Semior
  • one
    Judging by the passage that you indicated, the problem is in your quotes, where it is not correctly displayed, in the end you have the text not <tr><td> a .$head1; echo .$head1; echo - Bookin
  • Quotes are placed correctly, their number is even. And it first starts outputting "method; foreach ($ foo as $ element) {$ head1 = $ element ['head1']; $ head2 = $ element ['head2']; echo" ";}?>", That is, problem with output somewhere before this piece of code - Semior

1 answer 1

Php does not take "-> as a html comment", he knows what it is, well, at least in html it is still <!-- --> . I didn’t understand what the problem was with you, but in the code you missed the closing tag </td>

 echo "<tr><td>".$head1; echo "</td><td>".$head2; echo "</tr>"; 

It should be:

 echo "<tr><td>".$head1; echo "</td><td>".$head2."</td>"; echo "</tr>"; 

Not to be confused with the conclusions and stitching of the lines, as an example:

 <?php $foo = Class->method; ?> <?php foreach($foo as $element){?> <tr> <td><php echo $element['head1'];?></td> <td><php echo $element['head1'];?></td> </tr> <?php} ?> 
  • I know, I noticed and corrected it. The problem is that it also outputs method; foreach ($ foo as $ element) {$ head1 = $ element ['head1']; $ head2 = $ element ['head2']; echo ""; }?>, but does not perform it - Semior
  • So you write Class->method ? What is a Class ? - Bookin
  • Well, using the class is new ClassName()->methodName() or ClassName::methodName() and other options, what of this in your code? - Bookin
  • $ foo = NameSpace :: $ Instance-> Method (args); The amendment, as it turned out, is not a static class, but the only existing instance of the class. - Semior
  • Not sure of course, but I think that your static $Instance property may be empty. Maybe look in the logs for errors. - Bookin