Permalink
Browse files

bug #2502 Use class_exists instead of require (ogizanagi)

This PR was merged into the 1.x branch.

Discussion
----------

Use class_exists instead of require

I think this is required for symfony/symfony#23073 to pass. It's probably very similar to symfony/symfony#22657.

A simple reproducer:

```php
<?php

use Twig\Node\Node;

require_once __DIR__ . '/vendor/autoload.php';

new Node();
new \Twig_Node();
```

[Without this patch](https://travis-ci.org/symfony/symfony/jobs/239712676#L2100):

```php
PHP Fatal error:  Cannot declare class Twig_Node, because the name is already in use in vendor/twig/twig/lib/Twig/Node.php on line 20
```

With, everything works fine, whatever the two calls order.

Commits
-------

2c174e4 Use class_exists instead of require
  • Loading branch information...
fabpot committed Jun 5, 2017
2 parents 1af645d + 2c174e4 commit 84631789a2b1e326fc3cdce40f4335b37f327525
Showing with 156 additions and 156 deletions.
  1. +1 −1 src/Cache/FilesystemCache.php
  2. +1 −1 src/Cache/NullCache.php
  3. +1 −1 src/Compiler.php
  4. +1 −1 src/Environment.php
  5. +1 −1 src/Error/Error.php
  6. +1 −1 src/Error/LoaderError.php
  7. +1 −1 src/Error/RuntimeError.php
  8. +1 −1 src/Error/SyntaxError.php
  9. +1 −1 src/ExpressionParser.php
  10. +1 −1 src/Extension/AbstractExtension.php
  11. +1 −1 src/Extension/CoreExtension.php
  12. +1 −1 src/Extension/DebugExtension.php
  13. +1 −1 src/Extension/EscaperExtension.php
  14. +1 −1 src/Extension/OptimizerExtension.php
  15. +1 −1 src/Extension/ProfilerExtension.php
  16. +1 −1 src/Extension/SandboxExtension.php
  17. +1 −1 src/Extension/StagingExtension.php
  18. +1 −1 src/Extension/StringLoaderExtension.php
  19. +1 −1 src/FileExtensionEscapingStrategy.php
  20. +1 −1 src/Lexer.php
  21. +1 −1 src/Loader/ArrayLoader.php
  22. +1 −1 src/Loader/ChainLoader.php
  23. +1 −1 src/Loader/FilesystemLoader.php
  24. +1 −1 src/Markup.php
  25. +1 −1 src/Node/AutoEscapeNode.php
  26. +1 −1 src/Node/BlockNode.php
  27. +1 −1 src/Node/BlockReferenceNode.php
  28. +1 −1 src/Node/BodyNode.php
  29. +1 −1 src/Node/CheckSecurityNode.php
  30. +1 −1 src/Node/DoNode.php
  31. +1 −1 src/Node/EmbedNode.php
  32. +1 −1 src/Node/Expression/AbstractExpression.php
  33. +1 −1 src/Node/Expression/ArrayExpression.php
  34. +1 −1 src/Node/Expression/AssignNameExpression.php
  35. +1 −1 src/Node/Expression/Binary/AbstractBinary.php
  36. +1 −1 src/Node/Expression/Binary/AddBinary.php
  37. +1 −1 src/Node/Expression/Binary/AndBinary.php
  38. +1 −1 src/Node/Expression/Binary/BitwiseAndBinary.php
  39. +1 −1 src/Node/Expression/Binary/BitwiseOrBinary.php
  40. +1 −1 src/Node/Expression/Binary/BitwiseXorBinary.php
  41. +1 −1 src/Node/Expression/Binary/ConcatBinary.php
  42. +1 −1 src/Node/Expression/Binary/DivBinary.php
  43. +1 −1 src/Node/Expression/Binary/EndsWithBinary.php
  44. +1 −1 src/Node/Expression/Binary/EqualBinary.php
  45. +1 −1 src/Node/Expression/Binary/FloorDivBinary.php
  46. +1 −1 src/Node/Expression/Binary/GreaterBinary.php
  47. +1 −1 src/Node/Expression/Binary/GreaterEqualBinary.php
  48. +1 −1 src/Node/Expression/Binary/InBinary.php
  49. +1 −1 src/Node/Expression/Binary/LessBinary.php
  50. +1 −1 src/Node/Expression/Binary/LessEqualBinary.php
  51. +1 −1 src/Node/Expression/Binary/MatchesBinary.php
  52. +1 −1 src/Node/Expression/Binary/ModBinary.php
  53. +1 −1 src/Node/Expression/Binary/MulBinary.php
  54. +1 −1 src/Node/Expression/Binary/NotEqualBinary.php
  55. +1 −1 src/Node/Expression/Binary/NotInBinary.php
  56. +1 −1 src/Node/Expression/Binary/OrBinary.php
  57. +1 −1 src/Node/Expression/Binary/PowerBinary.php
  58. +1 −1 src/Node/Expression/Binary/RangeBinary.php
  59. +1 −1 src/Node/Expression/Binary/StartsWithBinary.php
  60. +1 −1 src/Node/Expression/Binary/SubBinary.php
  61. +1 −1 src/Node/Expression/BlockReferenceExpression.php
  62. +1 −1 src/Node/Expression/CallExpression.php
  63. +1 −1 src/Node/Expression/ConditionalExpression.php
  64. +1 −1 src/Node/Expression/ConstantExpression.php
  65. +1 −1 src/Node/Expression/Filter/DefaultFilter.php
  66. +1 −1 src/Node/Expression/FilterExpression.php
  67. +1 −1 src/Node/Expression/FunctionExpression.php
  68. +1 −1 src/Node/Expression/GetAttrExpression.php
  69. +1 −1 src/Node/Expression/MethodCallExpression.php
  70. +1 −1 src/Node/Expression/NameExpression.php
  71. +1 −1 src/Node/Expression/NullCoalesceExpression.php
  72. +1 −1 src/Node/Expression/ParentExpression.php
  73. +1 −1 src/Node/Expression/TempNameExpression.php
  74. +1 −1 src/Node/Expression/Test/ConstantTest.php
  75. +1 −1 src/Node/Expression/Test/DefinedTest.php
  76. +1 −1 src/Node/Expression/Test/DivisiblebyTest.php
  77. +1 −1 src/Node/Expression/Test/EvenTest.php
  78. +1 −1 src/Node/Expression/Test/NullTest.php
  79. +1 −1 src/Node/Expression/Test/OddTest.php
  80. +1 −1 src/Node/Expression/Test/SameasTest.php
  81. +1 −1 src/Node/Expression/TestExpression.php
  82. +1 −1 src/Node/Expression/Unary/AbstractUnary.php
  83. +1 −1 src/Node/Expression/Unary/NegUnary.php
  84. +1 −1 src/Node/Expression/Unary/NotUnary.php
  85. +1 −1 src/Node/Expression/Unary/PosUnary.php
  86. +1 −1 src/Node/FlushNode.php
  87. +1 −1 src/Node/ForLoopNode.php
  88. +1 −1 src/Node/ForNode.php
  89. +1 −1 src/Node/IfNode.php
  90. +1 −1 src/Node/ImportNode.php
  91. +1 −1 src/Node/IncludeNode.php
  92. +1 −1 src/Node/MacroNode.php
  93. +1 −1 src/Node/ModuleNode.php
  94. +1 −1 src/Node/Node.php
  95. +1 −1 src/Node/PrintNode.php
  96. +1 −1 src/Node/SandboxNode.php
  97. +1 −1 src/Node/SandboxedPrintNode.php
  98. +1 −1 src/Node/SetNode.php
  99. +1 −1 src/Node/SetTempNode.php
  100. +1 −1 src/Node/SpacelessNode.php
  101. +1 −1 src/Node/TextNode.php
  102. +1 −1 src/Node/WithNode.php
  103. +1 −1 src/NodeTraverser.php
  104. +1 −1 src/NodeVisitor/AbstractNodeVisitor.php
  105. +1 −1 src/NodeVisitor/EscaperNodeVisitor.php
  106. +1 −1 src/NodeVisitor/OptimizerNodeVisitor.php
  107. +1 −1 src/NodeVisitor/SafeAnalysisNodeVisitor.php
  108. +1 −1 src/NodeVisitor/SandboxNodeVisitor.php
  109. +1 −1 src/Parser.php
  110. +1 −1 src/Profiler/Dumper/BlackfireDumper.php
  111. +1 −1 src/Profiler/Dumper/HtmlDumper.php
  112. +1 −1 src/Profiler/Dumper/TextDumper.php
  113. +1 −1 src/Profiler/Node/EnterProfileNode.php
  114. +1 −1 src/Profiler/Node/LeaveProfileNode.php
  115. +1 −1 src/Profiler/NodeVisitor/ProfilerNodeVisitor.php
  116. +1 −1 src/Profiler/Profile.php
  117. +1 −1 src/RuntimeLoader/ContainerRuntimeLoader.php
  118. +1 −1 src/RuntimeLoader/FactoryRuntimeLoader.php
  119. +1 −1 src/Sandbox/SecurityError.php
  120. +1 −1 src/Sandbox/SecurityNotAllowedFilterError.php
  121. +1 −1 src/Sandbox/SecurityNotAllowedFunctionError.php
  122. +1 −1 src/Sandbox/SecurityNotAllowedMethodError.php
  123. +1 −1 src/Sandbox/SecurityNotAllowedPropertyError.php
  124. +1 −1 src/Sandbox/SecurityNotAllowedTagError.php
  125. +1 −1 src/Sandbox/SecurityPolicy.php
  126. +1 −1 src/Source.php
  127. +1 −1 src/Template.php
  128. +1 −1 src/TemplateWrapper.php
  129. +1 −1 src/Test/IntegrationTestCase.php
  130. +1 −1 src/Test/NodeTestCase.php
  131. +1 −1 src/Token.php
  132. +1 −1 src/TokenParser/AbstractTokenParser.php
  133. +1 −1 src/TokenParser/AutoEscapeTokenParser.php
  134. +1 −1 src/TokenParser/BlockTokenParser.php
  135. +1 −1 src/TokenParser/DoTokenParser.php
  136. +1 −1 src/TokenParser/EmbedTokenParser.php
  137. +1 −1 src/TokenParser/ExtendsTokenParser.php
  138. +1 −1 src/TokenParser/FilterTokenParser.php
  139. +1 −1 src/TokenParser/FlushTokenParser.php
  140. +1 −1 src/TokenParser/ForTokenParser.php
  141. +1 −1 src/TokenParser/FromTokenParser.php
  142. +1 −1 src/TokenParser/IfTokenParser.php
  143. +1 −1 src/TokenParser/ImportTokenParser.php
  144. +1 −1 src/TokenParser/IncludeTokenParser.php
  145. +1 −1 src/TokenParser/MacroTokenParser.php
  146. +1 −1 src/TokenParser/SandboxTokenParser.php
  147. +1 −1 src/TokenParser/SetTokenParser.php
  148. +1 −1 src/TokenParser/SpacelessTokenParser.php
  149. +1 −1 src/TokenParser/UseTokenParser.php
  150. +1 −1 src/TokenParser/WithTokenParser.php
  151. +1 −1 src/TokenStream.php
  152. +1 −1 src/TwigFilter.php
  153. +1 −1 src/TwigFunction.php
  154. +1 −1 src/TwigTest.php
  155. +1 −1 src/Util/DeprecationCollector.php
  156. +1 −1 src/Util/TemplateDirIterator.php
@@ -2,7 +2,7 @@
namespace Twig\Cache;
require __DIR__.'/../../lib/Twig/Cache/Filesystem.php';
class_exists('Twig_Cache_Filesystem');
if (\false) {
class FilesystemCache extends \Twig_Cache_Filesystem
View
@@ -2,7 +2,7 @@
namespace Twig\Cache;
require __DIR__.'/../../lib/Twig/Cache/Null.php';
class_exists('Twig_Cache_Null');
if (\false) {
class NullCache extends \Twig_Cache_Null
View
@@ -2,7 +2,7 @@
namespace Twig;
require __DIR__.'/../lib/Twig/Compiler.php';
class_exists('Twig_Compiler');
if (\false) {
class Compiler extends \Twig_Compiler
View
@@ -2,7 +2,7 @@
namespace Twig;
require __DIR__.'/../lib/Twig/Environment.php';
class_exists('Twig_Environment');
if (\false) {
class Environment extends \Twig_Environment
View
@@ -2,7 +2,7 @@
namespace Twig\Error;
require __DIR__.'/../../lib/Twig/Error.php';
class_exists('Twig_Error');
if (\false) {
class Error extends \Twig_Error
@@ -2,7 +2,7 @@
namespace Twig\Error;
require __DIR__.'/../../lib/Twig/Error/Loader.php';
class_exists('Twig_Error_Loader');
if (\false) {
class LoaderError extends \Twig_Error_Loader
@@ -2,7 +2,7 @@
namespace Twig\Error;
require __DIR__.'/../../lib/Twig/Error/Runtime.php';
class_exists('Twig_Error_Runtime');
if (\false) {
class RuntimeError extends \Twig_Error_Runtime
@@ -2,7 +2,7 @@
namespace Twig\Error;
require __DIR__.'/../../lib/Twig/Error/Syntax.php';
class_exists('Twig_Error_Syntax');
if (\false) {
class SyntaxError extends \Twig_Error_Syntax
View
@@ -2,7 +2,7 @@
namespace Twig;
require __DIR__.'/../lib/Twig/ExpressionParser.php';
class_exists('Twig_ExpressionParser');
if (\false) {
class ExpressionParser extends \Twig_ExpressionParser
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension.php';
class_exists('Twig_Extension');
if (\false) {
class AbstractExtension extends \Twig_Extension
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Core.php';
class_exists('Twig_Extension_Core');
if (\false) {
class CoreExtension extends \Twig_Extension_Core
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Debug.php';
class_exists('Twig_Extension_Debug');
if (\false) {
class DebugExtension extends \Twig_Extension_Debug
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Escaper.php';
class_exists('Twig_Extension_Escaper');
if (\false) {
class EscaperExtension extends \Twig_Extension_Escaper
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Optimizer.php';
class_exists('Twig_Extension_Optimizer');
if (\false) {
class OptimizerExtension extends \Twig_Extension_Optimizer
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Profiler.php';
class_exists('Twig_Extension_Profiler');
if (\false) {
class ProfilerExtension extends \Twig_Extension_Profiler
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Sandbox.php';
class_exists('Twig_Extension_Sandbox');
if (\false) {
class SandboxExtension extends \Twig_Extension_Sandbox
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/Staging.php';
class_exists('Twig_Extension_Staging');
if (\false) {
class StagingExtension extends \Twig_Extension_Staging
@@ -2,7 +2,7 @@
namespace Twig\Extension;
require __DIR__.'/../../lib/Twig/Extension/StringLoader.php';
class_exists('Twig_Extension_StringLoader');
if (\false) {
class StringLoaderExtension extends \Twig_Extension_StringLoader
@@ -2,7 +2,7 @@
namespace Twig;
require __DIR__.'/../lib/Twig/FileExtensionEscapingStrategy.php';
class_exists('Twig_FileExtensionEscapingStrategy');
if (\false) {
class FileExtensionEscapingStrategy extends \Twig_FileExtensionEscapingStrategy
View
@@ -2,7 +2,7 @@
namespace Twig;
require __DIR__.'/../lib/Twig/Lexer.php';
class_exists('Twig_Lexer');
if (\false) {
class Lexer extends \Twig_Lexer
@@ -2,7 +2,7 @@
namespace Twig\Loader;
require __DIR__.'/../../lib/Twig/Loader/Array.php';
class_exists('Twig_Loader_Array');
if (\false) {
class ArrayLoader extends \Twig_Loader_Array
@@ -2,7 +2,7 @@
namespace Twig\Loader;
require __DIR__.'/../../lib/Twig/Loader/Chain.php';
class_exists('Twig_Loader_Chain');
if (\false) {
class ChainLoader extends \Twig_Loader_Chain
@@ -2,7 +2,7 @@
namespace Twig\Loader;
require __DIR__.'/../../lib/Twig/Loader/Filesystem.php';
class_exists('Twig_Loader_Filesystem');
if (\false) {
class FilesystemLoader extends \Twig_Loader_Filesystem
View
@@ -2,7 +2,7 @@
namespace Twig;
require __DIR__.'/../lib/Twig/Markup.php';
class_exists('Twig_Markup');
if (\false) {
class Markup extends \Twig_Markup
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/AutoEscape.php';
class_exists('Twig_Node_AutoEscape');
if (\false) {
class AutoEscapeNode extends \Twig_Node_AutoEscape
View
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/Block.php';
class_exists('Twig_Node_Block');
if (\false) {
class BlockNode extends \Twig_Node_Block
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/BlockReference.php';
class_exists('Twig_Node_BlockReference');
if (\false) {
class BlockReferenceNode extends \Twig_Node_BlockReference
View
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/Body.php';
class_exists('Twig_Node_Body');
if (\false) {
class BodyNode extends \Twig_Node_Body
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/CheckSecurity.php';
class_exists('Twig_Node_CheckSecurity');
if (\false) {
class CheckSecurityNode extends \Twig_Node_CheckSecurity
View
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/Do.php';
class_exists('Twig_Node_Do');
if (\false) {
class DoNode extends \Twig_Node_Do
View
@@ -2,7 +2,7 @@
namespace Twig\Node;
require __DIR__.'/../../lib/Twig/Node/Embed.php';
class_exists('Twig_Node_Embed');
if (\false) {
class EmbedNode extends \Twig_Node_Embed
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression;
require __DIR__.'/../../../lib/Twig/Node/Expression.php';
class_exists('Twig_Node_Expression');
if (\false) {
class AbstractExpression extends \Twig_Node_Expression
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression;
require __DIR__.'/../../../lib/Twig/Node/Expression/Array.php';
class_exists('Twig_Node_Expression_Array');
if (\false) {
class ArrayExpression extends \Twig_Node_Expression_Array
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression;
require __DIR__.'/../../../lib/Twig/Node/Expression/AssignName.php';
class_exists('Twig_Node_Expression_AssignName');
if (\false) {
class AssignNameExpression extends \Twig_Node_Expression_AssignName
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary.php';
class_exists('Twig_Node_Expression_Binary');
if (\false) {
class AbstractBinary extends \Twig_Node_Expression_Binary
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/Add.php';
class_exists('Twig_Node_Expression_Binary_Add');
if (\false) {
class AddBinary extends \Twig_Node_Expression_Binary_Add
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/And.php';
class_exists('Twig_Node_Expression_Binary_And');
if (\false) {
class AndBinary extends \Twig_Node_Expression_Binary_And
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/BitwiseAnd.php';
class_exists('Twig_Node_Expression_Binary_BitwiseAnd');
if (\false) {
class BitwiseAndBinary extends \Twig_Node_Expression_Binary_BitwiseAnd
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/BitwiseOr.php';
class_exists('Twig_Node_Expression_Binary_BitwiseOr');
if (\false) {
class BitwiseOrBinary extends \Twig_Node_Expression_Binary_BitwiseOr
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/BitwiseXor.php';
class_exists('Twig_Node_Expression_Binary_BitwiseXor');
if (\false) {
class BitwiseXorBinary extends \Twig_Node_Expression_Binary_BitwiseXor
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/Concat.php';
class_exists('Twig_Node_Expression_Binary_Concat');
if (\false) {
class ConcatBinary extends \Twig_Node_Expression_Binary_Concat
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/Div.php';
class_exists('Twig_Node_Expression_Binary_Div');
if (\false) {
class DivBinary extends \Twig_Node_Expression_Binary_Div
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/EndsWith.php';
class_exists('Twig_Node_Expression_Binary_EndsWith');
if (\false) {
class EndsWithBinary extends \Twig_Node_Expression_Binary_EndsWith
@@ -2,7 +2,7 @@
namespace Twig\Node\Expression\Binary;
require __DIR__.'/../../../../lib/Twig/Node/Expression/Binary/Equal.php';
class_exists('Twig_Node_Expression_Binary_Equal');
if (\false) {
class EqualBinary extends \Twig_Node_Expression_Binary_Equal
Oops, something went wrong.

0 comments on commit 8463178

Please sign in to comment.