0

Are there any caveats one should be aware of when using the alternative PHP tags:

<script language="php">
    // ...
</script>

I've tested in 5.2.X through 5.4.X with no issues, however I cannot find exhaustive information on the topic. My greatest concern is sudden deprecation. Any information about support for this alternative would be great.


To answer those asking "Why the heck do you want to use that anyways?", I'm using PHP in XML files, where the surrounding XML acts as meta-data to the script contained therein. Unfortunately, XSD cannot validate processing instruction nodes, er go, using an element tag to wrap the PHP would simplify the validation process. This would keep the semantic value.

As it stands I need to validate against the XSD, and perform a post-validation sweep using XPath to check for processing instruction nodes.

4
  • 1
    Just as a side comment, the server configuration requires that support for this tag style must be enabled. Check to be sure that your production server has this style enabled, or, better yet, if you can enable it yourself. Commented May 26, 2012 at 19:12
  • Your script won't be valid XML in any way, unless you at least escape > and < (also in -> or => operators...) Commented May 26, 2012 at 19:43
  • @johannes Yea, that's true. I've been using the processing instruction approach thus far (I only have to escape ?>, which is very inoften), and the documents are valid. Perhaps I'm just better to do that. Commented May 26, 2012 at 21:33
  • It's also worth noting, that given the purpose for script inclusion, most often PHP's not parsing the file directly. Knowing this, it's somewhat a moot point, however I'm interested in maintaining consistency across files in the project when possible anyway. Commented May 27, 2012 at 0:07

2 Answers 2

2

According to the PHP documentation:

While the tags seen in examples one [ <?php ?> ] and two [ <script> ... </script> ]are both always available, example one is the most commonly used, and recommended, of the two.

So no, it probably will not be deprecated, although <?php ?> seems to be recommended.

Sign up to request clarification or add additional context in comments.

Comments

1

The commonly known alternative PHP tags (ASP tags <% %>, <%=, and the script tag <script language="php"> and their respective directives) were proposed and accepted to be removed starting version 7.0.

The only help offered nowadays is a just a porting script to replace them. You may wanna check it to keep your code up-to-date.

There's also a short tag available just for displaying values. It only saves you the explicit declaration of echo and printing functions. Before version 5.4.0 it needs to be enabled via short_open_tag=On on the php.ini file.

<?= $previouslyDeclaredValue ?>

Smarty and Laravel blade are examples of template engines that enable the use of predefined and custom tags as alternatives that depend upon the installation of its corresponding platforms. Their core purpose is template design.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.