I have come across an issue with composer and PHP short tags <?
.
Take this code below.
<?
namespace SPACENAME;
class generic_class {
private $class_name = 'this_is_a_test';
/**
* This function is used to return the class name property.
*/
public function some_function() {
return true;
}
}
?>
If you notice, we have a class called generic_class
and a comment that contains the words class name , and are using PHP's short tags <?
When I do a composer update my autoload class shows the following:
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'SPACENAME\name' => $vendorDir . '/the/path/to/generic_class.php'
);
?>
It seems to pick up the words class name in the comment and treats that as a class definition instead of using the actual class definition of generic_class
. However if I use PHP's full tags <?php
then this issue doesn't happen and my autoload class is correct.
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'SPACENAME\generic_class' => $vendorDir . '/the/path/to/generic_class.php'
);
?>
So, in one way I have fixed the issue by swapping my short tags to full tags. However I am currently working in a fairly large team who all use composer for the same project and do not get this issue with short tags. I can't see me being able to change their usage/opinion on short tags so I am hoping someone has a solution or at least an answer as to why this may be happening on my machine and no one elses?
I did try to google for the answer but came up with nothing, is there a composer setting that stops it recognizing short tags as valid php therefore it is unable to know what is code and what is a comment?
Information that might be helpful
We all have the same OS (Windows).
We are all on the same version of composer.
We are all working from the same codebase.
There are 8 of us working on the project at the moment.
We all have our PHP servers set up differently, I am the only one who uses WAMPSERVER 3.
Basically you need just to disable short tags in your configuration. Just set
short_open_tag=0
in your php.ini
. Please, be careful: the php interpreter used by composed sometimes has a different php.ini
with respect to the Apache version.
See: http://php.net/manual/en/ini.core.php#ini.short-open-tag
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.