Dan Lugg
Dan Lugg

Reputation: 20612

PHP <script language="php"> tags

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.

Upvotes: 0

Views: 1624

Answers (2)

Christian L&#230;irbag
Christian L&#230;irbag

Reputation: 338

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.

Upvotes: 1

Arka
Arka

Reputation: 837

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.

Upvotes: 2

Related Questions