Missing `<?php` tags?
I'm not experience enough with PHP to know the source of the issue, but I've been working my way through the tutorial and when I got to the "try it out!" step at the end of "Database and Models" the contents of my PHP files were being displayed verbatim. I had to go back through and add <?php to the beginning of the all the .php files I had created, and now everything works. For what it's worth I'm using Apache as the server.
Did I miss something in the tutorial that would cover this? Do not all web servers require a PHP tag at the beginning of the file anymore?
The examples most skip the initial PHP declaring marker as they assume you already are in PHP scope: are there specific examples where this is particularly unclear?
On Mon, May 17, 2021, 03:39 RussellAult @.***> wrote:
I'm not experience enough with PHP to know the source of the issue, but I've been working my way through the tutorial and when I got to the "try it out!" step at the end of "Database and Models" the contents of my PHP files were being displayed verbatim. I had to go back through and add <?php to the beginning of the all the .php files I had created, and now everything works. For what it's worth I'm using Apache as the server.
Did I miss something in the tutorial that would cover this? Do not all web servers require a PHP tag at the beginning of the file anymore?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/laminas/tutorials/issues/46, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFVEEBGOVCST74AZ35MFDTOBXU7ANCNFSM447PLK7Q .
@Ocramius Perhaps I'm not the target audience, but the last time I did anything that might be called "web development" was before application frameworks were a thing, so when an instruction says "Let's create that file now, with the following contents:" I follow those instructions verbatim. So, at a minimum, every time the entire contents of a particular file except for the <?php tag is given, it's particularly unclear to me that the tag has been omitted (especially because the convention isn't mentioned anywhere).
Is there an advantage to omitting the <?php tag?
Also, part of my confusion stems from the fact that sometimes (like with .phtml files) the <?php tag is included explicitly, which reinforces the impression that it's not necessary in the other files.
Is there an advantage to omitting the
<?phptag?
Generally yes, as examples are very often isolated to code fragments, rather than entire files. We also don't include things like the current namespace, or all the imports, since docs are for reference, not copy-pasteable code in most cases.
For .phtml files, the PHP tag is included explicitly because by default, you are operating within text output context, rather than in PHP context.
Other libraries/tools in the PHP ecosystem also omit the opening <?php declaration in docs, but perhaps confusion for newcomers should be a signal that this could change for laminas/tutorials perhaps? /cc @froschdesign
I think that makes a lot of sense for the fragments.
For me, the confusion stems from the fact that, unlike with most documentation, several of the examples in the tutorial imply that they are the entire contents of a given file (i.e. I think it's confusing when every line of a file is shown except for the first one).
@RussellAult
Perhaps I'm not the target audience…
The target group are experienced PHP programmers because it is not the task of the documentation to explain the basics. Unfortunately, this would go beyond any capacities.
But the current plan already includes this topic and we will provide the full code and add links in the documentation. But before that, we will rework the tutorial.