Session error using Laravel PHP - php

I get this error when enabling sessions, using the filesystem, in Laravel PHP.
Only variables should be passed by reference in SYS_PATH/session.php on line 230.
Stack Trace:
0 /Applications/XAMPP/xamppfiles/htdocs/laravel/system/session.php(230): System\{closure}(2048, 'Only variables ...', '/Applications/X...', 230, Array)
1 /Applications/XAMPP/xamppfiles/htdocs/laravel/system/session.php(190): System\Session::write_cookie()
2 /Applications/XAMPP/xamppfiles/htdocs/laravel/system/laravel.php(187): System\Session::close()
3 /Applications/XAMPP/xamppfiles/htdocs/laravel/public/index.php(44): require('/Applications/X...')
4 {main}
Snapshot:
225: */
226: private static function write_cookie()
227: {
228: if ( ! headers_sent())
229: {
230: extract(Config::get('session'));
231:
232: $minutes = ($expire_on_close) ? 0 : $lifetime;
233:
234: Cookie::put('laravel_session', static::$session['id'], $minutes, $path, $domain, $https, $http_only);
235: }
Has anybody run into this issue? Even if you don't use Laravel, any insight?

That you're seeing the error message is a flaw in the Laravel PHP framework.
The session class makes use of the extract function that is expecting a variable, but it get's a function return.
I have reported this behavior to the project and you can discuss the options with them as well. You find a suggestion how to fix it attached, let me know if that works for you.

What if instead of extracting the config to your local scope you just assign it to an array, and use those values? The error seems to be there, not with sessions.

Related

Wordpress Custom Import Plugin Not working

I have a wordpress custom import plugin which was working fine, but for some reason it is not working in a new wordpress install Dropbox link. Plugin looks for two feed files barneys_feed.txt & barneyswarehouse_feed.txt (included with plugin) which should be configured in plugin settings page Detailed Description. On activation a custom table has to be created but not creating and on product run following is displayed in log:
[Tue Nov 22 18:28:08.931419 2016] [:error] [pid 11484] [client 38.140.212.19:64906] PHP Catchable fatal error: Argument 1 passed to sjr\\product_import\\SJR_Product_Import::get_line() must be an instance of SplFileObject, null given, called in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 334 and defined in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 372, referer: http://testwindow.wpengine.com/wp-admin/options-general.php?page=sjr_product_import_settings
Not able to reach out plugin developers. Please help. Thanks.
Update:
Following is the error i am getting now.
PHP Fatal error: Uncaught TypeError: Argument 1 passed to sjr\\product_import\\SJR_Product_Import::get_line() must be an instance of SplFileObject, null given, called in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 334 and defined in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php:372\nStack trace:\n#0 /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php(334): sjr\\product_import\\SJR_Product_Import->get_line(NULL, 1)\n#1 [internal function]: sjr\\product_import\\SJR_Product_Import->csv_to_database()\n#2 /nas/content/live/testwindow/wp-includes/plugin.php(600): call_user_func_array(Array, Array)\n#3 /nas/content/live/testwindow/wp-cron.php(117): do_action_ref_array('sjr_product_imp...', Array)\n#4 {main}\n thrown in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 372, referer: http://testwindow.wpengine.com/wp-cron.php?doing_wp_cron=1480412579.4279830455780029296875
Something I find helpful for debugging these kinds of issues is looking at the stack trace of where your error is. You can print the stack trace at each of the debug_backtrace() at each of the locations you call get_line to see what is on the stack when you get the failed call.
I don't have your project up at this time, but it looks like your $file object is no longer in scope (and therefore null) for this call to get_line
foreach( $lines as $line_item ){
if( $file_name != $line_item['file'] ){
$file_name = $line_item['file'];
$basename = basename( $file_name );
// get columns
$file = new \SplFileObject( $file_name, 'r' );
$file->setFlags( \SplFileObject::READ_CSV );
$file->setCsvControl( "\t", " " );
// get first row with column names
$first_row = $this->get_line( $file, 0 );
} // You lose scope on $file here
$row = $this->get_line( $file, $line_item['line_number'] - 1 ); // <-- This one is the likely cause
You should do two things here:
Define $file before the if statement (likely as $file = null)
Handle the case of still having a null $file object after the if statement and before the problem get_line call.
The error message tells you, that at some point, the get_line function of sjr\product_import\SJR_Product_Import gets instead of an instance of SplFileObject just a null.
I'm guessing the get_line function looks something like this:
public function get_line(SplFileObject $file) { /* do some stuff */ }
What you can either do (assuming you wrote that code on your own), is to change the function to something like this:
public function get_line(SplFileObject $file=null) { /* do some stuff */ }
telling PHP that besides the object, you also accept null as a default value. In that case, you would have to update your function, to check if the given variable is null. You can check this for example with
if (!is_null($file)) {
/* every thing is fine */
} else {
/* there was an error, maybe write it to a error log */
}
A completely guess from my side, as the error states, that the location contains /nas/ I'm assuming, that the PHP code is run on a NAS and has some drives mapped, from which you try to import some stuff periodically, as the import is started by a cron job. Maybe one of those mapped drives somehow lost the connection and therefore PHP wasn't able to read the files. But as I said, that's just a wild guess. To "debug" this, you could check the status of the mapped drives manually when the cron job is run and see, if the problem still happens. Another thing could be, that PHP (or more precise, Apache or Nginx) doesn't have rights to access those files/shares.

Smarty3 upgrade to PHP7 and weird problems with register plugin

I have an existing, well functional PHP Application. I am looking into an server upgrade which includes moving from PHP5 to PHP7. As far as I can tell from the documentation Smarty3 should be compatible with PHP7. However, when testing this, it turns out that Smarty refuses to compile the templates after the upgrade.
The source of the problem seems to be this line:
$this->smarty->registerPlugin('compiler', 'asset_url', array(&$this, 'asset_url'));
which causes the PHP application to crash like this:
Notice: Array to string conversion in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
Notice: Undefined property: template::$Array in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
Fatal error: Uncaught Error: Function name must be a string in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php:415
Stack trace:
#0 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(3585): Smarty_Internal_TemplateCompilerBase->compileTag('asset_url', Array)
#1 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(4413): Smarty_Internal_Templateparser->yy_r32()
#2 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(4515): Smarty_Internal_Templateparser->yy_reduce(32)
#3 /usr/share/php/smarty3/sysplugins/smarty_internal_smartytemplatecompiler.php(118): Smarty_Internal_Templateparser->doParse(3, '}')
#4 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(283): Smarty_Internal_SmartyTemplateCompiler->doCompile('<!DOCTYPE html>...')
#5 /usr/share/php/smarty3/sysplugins/smarty_internal_template.php(197): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#6 /usr/share/php/smarty3/sysplugins/sm in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
The suspicious line 415 looks like this:
$function = $this->smarty->registered_plugins[$plugin_type][$tag][0];
if (!is_array($function)) {
return $function($new_args, $this);
} elseif (is_object($function[0])) {
return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); <- Crash here!
} else {
return call_user_func_array($function, array($new_args, $this));
}
I assume this is some fundamental difference between PHP5 and PHP7 which is biting me, but I can't seem to figure out what it is. Could somebody give me a few pointers to how to sort this out?
If you're using an older version of Smarty, you might want to update. There were some fixes added in 3.1.28 for PHP 7 compatibility that will probably help with this.
See https://github.com/smarty-php/smarty/blob/master/change_log.txt
The explanation of this issue (besides the most common ones like "you have an outdated version") is that in PHP 7 it has been changed the way how code is parsed. In your case:
$this->smarty->registered_plugins[$plugin_type][$tag][0];
is parsed differently in PHP 5 and 7:
PHP 5: $this->smarty->{registered_plugins[$plugin_type][$tag][0]};
PHP 7: ($this->smarty->registered_plugins)[$plugin_type][$tag][0];
You can try fixing these code pieces by placing braces and brackets to indicate the parser what are your exact intentions, but I'd suggest you to upgrade Smarty.

How do I dump variables in Yii for debugging?

How do I dump and print variables in Yii for debugging? I would like to use var_dump() or print_r(). I tried to use Yii::trace() but it crashes with this error in runtime/logs/app.log. It doesn't even tell me the line in my code that it fails.
2015-03-18 20:54:11 [::1][-][-][warning][yii\log\Dispatcher::dispatch] Unable to send log via yii\debug\LogTarget: Exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed'
in /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.php:58
Stack trace:
#0 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.php(58): serialize(Array)
#1 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.php(112): yii\debug\LogTarget->export(Array)
#2 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2/log/Dispatcher.php(183): yii\debug\LogTarget->collect(Array, true)
#3 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2/log/Logger.php(170): yii\log\Dispatcher->dispatch(Array, true)
#4 [internal function]: yii\log\Logger->flush(true)
#5 {main}
Reference
http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
Because you are asking about something like var_dump and print_r, I can advise built-in helper for this. It's called yii\helpers\VarDumper. Yii::trace() is for logging trace messages.
VarDumper is intended to replace the buggy PHP function var_dump and print_r.
It can correctly identify the recursively referenced objects in a
complex object structure. It also has a recursive depth control to
avoid indefinite recursive display of some peculiar variables.
VarDumper can be used as follows,
VarDumper::dump($var);
Personally I don't use it, just tried only couple of times for testing.
I think is better to use Xdebug for that purposes.
See also PsySH.
Use this:
<?php echo '<pre>'; print_r($model); exit; ?>
I used this, but I'm sure there's a better way.
Yii::warning('**********************', var_export($category,true));
config/web.php
'log' => [
...
'flushInterval' => 1, // for debug
'targets' => [
[
...
'exportInterval' => 1, // for debug - slow
],
],
],
Use this, to see your variable or object array.
use yii\helpers\VarDumper;
VarDumper::dump($variableArray , $dept = 10, $highlight = true);
To detail you can read the doc
http://www.yiiframework.com/doc-2.0/yii-helpers-basevardumper.html#dump()-detail
You can do it yourself:
In your main index page (back/index.php or front/index.php) add this code to the top ob_start();. Then define 2 functions for better debugging
function dd($v){
ob_clean();
var_dump($v);
exit;
}
function dj($v){
ob_clean();
echo CJSON::encode($v);
exit;
}
and add ob_end_flush(); at the very end of your main index page . Now you can call dd($model) or dj($model). There you had your dumper working. Congratulations!
I had written an article about this problem with debug variables in Yii 2:
Since for the sake of Simplicity and Quick Development, I’ve created a helper for those who use Yii. You can just call dd($var1, $var2, ….); for dump & die or d($var1, $var2, ….); for dump data.
Details and installation instructions are on: https://dangnhsite.wordpress.com/2016/04/06/variable-debug-in-yii-2/

Laravel 3 - PHP Warning: in_array() expects parameter 2 to be array

I am working with a code that was not written by me. It is a Laravel 3 application, it is giving me the following error:
PHP Warning: in_array() expects parameter 2 to be array, null given in /Users/use/Documents/project/laravel/error.php on line 87
Can you give me pointers on how to debug it? It is giving error in the file which was included in the framework. Also I using the php's inbuilt server to run the application. Does that cause problems? Any pointers are helpful.
PS: I am on a mac.
After looking at the source code it appears that you are getting the error from this file:
// laravel/error.php
// line 86
if (in_array($code, Config::get('error.ignore')))
{
return static::log($exception);
}
The method appears to be looking for the error.ignore config variable:
// application/config/error.php
// line 16
'ignore' => array(),
Check the application/config/error.php file, make sure that 'ignore' is set to an array. If it already is, then you likely have an error in one of the other config files which is corrupting the array.
Hopefully this helps and shows the steps you can take in tracking down the source of an error.
You can get this also if you're using composer and the required files have not been installed after a fresh checkout of the project. To resolve:
$ composer install
Or similar. To actually get a head on this information I had to throw $exception in the error.php file around line 87, then I saw the reason in the Apache error logs.
Most of this errors is about of parameters definition bug.
for example sometimes coder write
protected $guarded = 'title';
instead of
protected $guarded = ['title'];
That makes the paroblem

Invalid Memcache->connection member variable errors

We are currently using Nginx as our server and memcached for caching mechanism. I was inspecting PHP error logs and lots of PHP Warnings about memcached caught my attention.
PHP Warning: Memcache::get(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 180
At the line it was pointing, there is this piece of code:
$tmp = $this->_memcache->get($id);
I also see many other PHP warnings with the same warning message but different with different function calls of memcache object:
PHP Warning: Memcache::add(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 180
PHP Warning: Memcache::set(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 230
PHP Warning: Memcache::delete(): Invalid Memcache->connection member variable in {directory}/library/Zend/Cache/Backend/Memcached.php on line 323
I did a search through the web but could not find anything that really helped. From time to time, we have some problems with our memcached. Is it possible that this some kind of issue that happens when servers are down because of some problem? I really do not have any idea about what causes these warnings. How can I correct it or at least how can I avoid these warnings?
I found 3 references that might help you
Limit of file system and memcache
Possible memory leaks
Memcache vs Memcached
You need to check key max 250 chars and value max : 1MB
Have you compiled your own php recently? It's possible ther versions are out of sync.
I had the same problem.
when i called memcache object in __destruct to update the state of my object i goot the error.
and here is my solution.:
call object in your class function where you change the state and be sure to send an instance of memcache to this class.
While from the warning message itself, it may not be obvious, but the error may be happening when you're trying to serialize/deserialize memcache connection object itself.
For example:
class a {
private Memcache $mc;
private $name = 'glen';
public function __construct(Memcache $mc) {
$this->mc = $mc;
}
}
$a = new a($mc);
$mc->set('a', $a);
You very likely (as me) ended up here because class having mixed concerns (the object being a model and has as other business logic as well). you can omit the unwanted mc key from serializing using __debugInfo function:
public function __debugInfo() {
return [];
}
https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo
While writing this note, I'm not able to reproduce with my own example, so there's something else involved, perhaps memory corruption. But removing $mc property solve the problem for me.

Categories