ClassNotFoundException in SecurityExtension.php line 20 - php

I have a quite mature project and I decided to move it to a different development environment. After setting everything up, I am now getting this exception:
ClassNotFoundException in SecurityExtension.php line 20:
Attempted to load class "Twig_Function_Method" from the global namespace.
Did you forget a "use" statement?
Where is this coming from? I am not even sure where to start.
By the stack trace, seems like it is something to do with assetic.
However, when I execute console command, for example cache:clear.
I am getting this:
[Symfony\Component\Debug\Exception\ClassNotFoundException]
Attempted to load class "Twig_Function_Method" from the global namespace.
Did you forget a "use" statement?
Similar, but now I am not even getting any more details than that.

Related

Class not found after "require_once"

I get the following error:
`Fatal error: Class 'DummyClass' not found in...`
<?php
require_once("3rdparty/simplesaml/lib/_autoload.php");
class login extends DummyClass { (this is the line the error refers to)
[...]
}
?>
If I comment out the require_once it works perfectly fine.
DummyClass is defined externally and can be found in the prepend-file. (I don't think it matters for this problem as it works as expected if I comment out require_once)
The path to the file should also be correct as it gives me a "Failed opening required..." Error if I change the path.
I also tried switching between PHP 5.6 and 7 - no difference.
So, I would like to ask you for help. Do you have any hints / ideas, why I might get that error?
Problem solved.
The old framework was using the old __autoload function, which is deprecated.
SimpleSAMLPHP used the new function. Those autoload-combinations cause one of them to override the other.
Solution:
Switch from __autoload to spl_autoload_register.
Similar Question: Override vendor autoload composer

'Twig_Error_Syntax' with message 'Unknown "render" filter

I'm running drupal 8, composer and npm to perform gulp tasks.
When I run npm start.. my task manager: I get the following stack trace:
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "render" filter.' in /web/project/web/themes/emulsify/components/_patterns/04-templates/basic-page/_basic_page.twig:26
Stack trace:
#0 /web/project/web/themes/emulsify/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(481): Twig_ExpressionParser->getFilterNodeClass('render', 26)
#1 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(466): Twig_ExpressionParser->parseFilterExpressionRaw(Object(Twig_Node_Expression_Name))
#2 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(320): Twig_ExpressionParser->parseFilterExpression(Object(Twig_Node_Expression_Name))
#3 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(212): Twig_ExpressionParser->parsePostfixExpression(Object(Twig_Node_Expression_Name))
#4 /web/project in /web/project/web/themes/project_theme/components/_patterns/04-templates/basic-page/_basic_page.twig on line 26
I've looked at installing twig-bridge / symfony twig via composer but I can't seem to get rid of the error message.
Do I just ditch using the twig filter "render"?
Update: 14/08/17
I've also ran into the same problem when trying to use the drupal_block function provided via Drupal 8's twig_tweak module.
The problem in the code above is that your Twig extension class is extending the internal Drupal Twig extension class. That breaks the Twig extensions added by Drupal core and that's why you are getting the error.
To fix this, you should make your Twig extensions extend Twigs internal Twig extension class. Your class should be defined like this:
class MyExtension extends \Twig_Extension {
After making that change, you can also remove arguments set for that class from the MODULE.services.yml
link
I've not seen this in the Drupal context, but working with other platforms that use Twig, I have seen similar issues occurring when an error occurs early in the platform setup process.
The typical sequence of events is like this:
The platform starts running its bootup; loading the CMS core, etc.
At some point early in this process, it hits an error.
It then tries to render an error page.
However, the error page uses a Twig template.
The startup process has not yet loaded all the twig extensions used in the template.
Boom, you get a twig error stating "unknown Twig function" instead of the real error message.
When I've had this before, it has proved very hard to diagnose what the actual error is.
The "correct" solution has been to modify the error page templates so that they are minimal and don't use any non-core twig functions. But if you're getting a crash early in the page load process it can be hard to actually do that.
In the first case, I resolved it by debugging the system and trapping what data was passed to the template. This showed me what the real error was. Resolving that error then stopped the twig error from occurring and allowed me to get into the system.
I don't know for sure if what you're seeing is the same kind of thing as what I was seeing, but it sounds similar so I hope this will help.

Symfony Assetic Dump get class not Found Exception

When I tries to assetic dump php app/console assetic:dump --env=prod, I got Error Like
[Symfony\Component\Debug\Exception\ClassNotFoundException]
Attempted to load class "Twig_Filter_Method" from the global namespace.
Did you forget a "use" statement?
In Browser Run my Project It is display error like :-
ClassNotFoundException in BootstrapIconExtension.php line 51:
Attempted to load class "Twig_Filter_Method" from the global namespace.
Did you forget a "use" statement?
Anyone have any Suggestion please let me know ..
Change
'apply_filter' => new \Twig_Filter_Method($this, 'applyFilter'),
to this
'apply_filter' => new \Twig_SimpleFilter('apply_filter', array($this, 'apply_filter')),
I had the same issue; for me it was related with the liip imagine bundle version i was using. I have changed that version and it worked smoothly

PHPUnit Mysteriously Fails On Object Constructor with require_once and $SERVER variable

I'm trying to wrap a test class around a pre-existing PHP class file that does not adhere to any PSR standard.
The PHP object I'm trying to test has a constructor that accepts 1 argument.
When prepping my object in setUp, my test correctly fails because there is a constructor argument missing. Because of this, I feel good that my object is being correctly resolved.
protected function setUp() {
$this->object = new HierarchyChange();
}
However, when I do add a value:
$this->object = new HierarchyChange('username');
NetBeans throws a "Perhaps error occurred, verify in Output window" message when I run the tests. And the output window has no information.
Executing "phpunit . -v" from the command line simply outputs the PHPUnit version I'm working with, but does not show any exception information.
I've tracked the failing line in my HierarchyChange class to this line in the class constructor:
public function __construct($agent_manager)
{
/* require contracting base class */
require_once($_SERVER['DOCUMENT_ROOT'] . '/_inc/oc.class.php');
I've tried a number of different ways to add this file, thinking that the server variable was causing the problem, but even removing it and hardcoding the path in the constructor cause the test suite to crash.
It DOES, however, work when I comment out the require_once line completely.
It doesn't make sense to me why this fails, but I am grasping at straws with this. Thanks.
The issue stemmed from a few things:
incorrect configuration of PHP.ini (error messages were not being raised), but more importantly:
incorrectly setting server vars; I ended up modifying the phpunit.xml configuration file to include:
Since the tests were being executed via CLI, these server variables are not available, so they needed to be set. And when phpunit encountered this as an error, NetBeans didn't know how to report it in the output window because the local INI configuration was not set to do so.

Can no longer install WordPress on MAMP- "Fatal error: Cannot redeclare class wpdb"

I've been developing WordPress sites for a long time on my local MAMP server. Now all of a sudden, it won't let me create any new sites. Whenever I set up a new one, instead of running the install script I get:
Fatal error: Cannot redeclare class
wpdb in
/Applications/MAMP/htdocs/[my_site]/wp-includes/wp-db.php
on line 52
This happens with all WordPress versions. I cannot thing of anything that would have caused this. I've done everything short of re-install MAMP. Does anyone have any ideas? I'm desperate at this point..
Check out the include path for php. It's likely that a second instance of wordpress is on the include path and is therefore conflicting with the one you're trying to load. It's also possible that a different package on the include path has a class called wpdb and is therefore causing a conflict.
wpdb is being created again some where, if this happened all of a sudden i suggest that you disable any plugins you've recently added. Or even better do a global find for the term class wpdb and see if that appears within more than 1 file. Also, check your functions.php file for a loop that might be loading wp-db.php more than once.
A workaround fix is to wrap the wpdp class in wp-includes/wp-db.php in the following:
Line 52:
if(class_exists('wpdb') != true)
{
class wpdb {
...
}
}
This solved the install issue- You could probably remove it after that, although it can't hurt to leave it I guess.
Still don't understand why this problem has popped up- If someone has an explanation I'd be eager to hear it.

Categories