[wp-trac] [WordPress Trac] #42517: get_file_data() doesn't support the single-line variant of post template headers

WordPress Trac noreply at wordpress.org
Sun Nov 12 19:12:35 UTC 2017


#42517: get_file_data() doesn't support the single-line variant of post template
headers
----------------------------------------+------------------------------
 Reporter:  gschoppe                    |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  General                     |     Version:  4.9
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+------------------------------

Comment (by gschoppe):

 If we were to go that route, I'd recommend removing all php tags, rather
 than just the first, as currently some php files certainly start with:
 {{{#!php
 <?php if ( ! defined( ABSPATH ) ) die()! ?>
 <?php // Template Name: My Template ?>
 }}}

 We could go oldschool and simply run
 {{{#!php
 <?php
 str_replace( array( '<?php', '<?', '?>' ), '', $file_data );
 }}}

 The end result shouldn't be effected by whether we remove one or 100 tags,
 though it may effect speed of algorithm.

 Not sure of the exact profiling, but my guess would be that a single
 initialization of the regex engine would be faster than multiple, or than
 a str_replace and a regex, but I am not certain of that.

 I'm also not certain of the weight of loading the regex engine multiple
 times vs running a regex that includes look-ahead queries, like mine.

 My knee jerk is to believe that a single regex is faster over an 8k
 dataset, even with look-aheads.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42517#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list