Member variable does not accept array with elements - php

After updating WordPress to 6.0.2, I get the "white screen of death" - just stating that
there is a critical error
with no further explanation.
After some debugging I located the line, that produces the error:
/wp-content/plugins/jet-theme-core/includes/locations.php line 53
It's a function of the class Jet_Theme_Core_Locations that assigns an array to $this->_locations[ $id ]
With these declarations
private $_locations = array();
public $test = array();
private $_test = array();
I tested some statements and found out that
$this->_locations = true; // works
$this->_locations = "test"; // works
$this->_locations = array(); // works
$this->_locations = array("test"); // produces a critical error
$this->_locations = array("test" => "test"); // produces a critical error
$this->_locations[] = "test"; // produces a critical error
$this->_locations["test"] = "test"; // produces a critical error
$test = array("test" => "test"); // works
$this->test = array(); // works
$this->test = array("test"); // works
$this->_test = array(); // works
$this->_test = array("test"); // works
I must be missing something. Probably something really obvious. But I can't figure out, what it is.
[Edit:]
The PHP log file says:
PHP Fatal error: Uncaught Error: Class 'Elementor\\Post_CSS_File' not found in /wp-content/plugins/jet-theme-core/includes/locations.php:106

The function enqueue_styles() loops over $this->_locations and calls Elementor\Post_CSS_File but doesn't find it. If $this->_locations is empty or not an array at all, it doesn't touch Elementor\Post_CSS_File and the error doesn't occur.
As suggested here, I replaced
$css_file = new Elementor\Post_CSS_File( $template_id );
with
$css_file = new Elementor\Core\Files\CSS\Post( $template_id );
Now everything works fine.

Related

Automatic conversion of false to array is deprecated

I get this warning in a chunk of instructions PHP 8+ dedicated to the check of the user inside the page:
if ($_POST['go'] ?? null) {
// $_SESSION_VALUES is an array $db, $nick are classes of mine
$_SESSION_VALUES = $nick->get_cookie (COOKIE_NAME); // get the name of the cookie
if ($db->check_user (USERS_TABLE, $_POST['nick'], $db->encode_password($_POST['password']))) {
$_SESSION_VALUES['_USERNAME'] = $db->user_rec['nick']; // get the nickname from the cookie
$_SESSION_VALUES['_PASSWORD'] = $db->user_rec['password']; //get the password
$_SESSION_VALUES['_USER'] = $db->user_type;
if (! $nick->set_cookie (COOKIE_NAME, $_SESSION_VALUES)) die ('Cannot write the cookie'); // record the cookie
header('Location: ./copertina'); }
else $_SESSION_VALUES['_USER'] = -1;
}
The execution of
else $_SESSION_VALUES['_USER'] = -1;
gives "Automatic conversion of false to array is deprecated"
Following a suggestion from stack overflow I tryed this:
$\_SESSION_VALUES = \[\];
if ($\_POST\['go'\] ?? null) {
...
but apparently it doesn't work
any idea?
Thanks
I assume that $nick->get_cookie(COOKIE_NAME); returns false.
Try changing:
else $_SESSION_VALUES['_USER'] = -1;
to:
else $_SESSION_VALUES = ['_USER' => -1];
This will probably get rid of the error message you reported, but I don't know if the rest of your code, which I cannot see, will accept this.

how to recognise that I am able to log in to rets?

how to recognise i am able to log in to rets ?
This is my code and output.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//date_default_timezone_set('America/New_York');
require_once("vendor/autoload.php");
//$log = new \Monolog\Logger('PHRETS');
//$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
$config = new \PHRETS\Configuration;
$config->setLoginUrl('*****************');
$config->setUsername('****');
$config->setPassword('****');
$config->setUserAgent('****');
$config->setRetsVersion('1.7.2');
$config->setOption('disable_follow_location',false);
$config->setOption('use_post_method',true);
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
$connect = $rets->Login();
var_dump($connect->getBody());
output
Notice:
Trying to get property of non-object in
/var/www/html/glvar/rets/vendor/troydavisson/phrets/src/Parsers/GetMetadata/System.php
on line 26
Fatal error:
Call to a member function attributes() on a non-object in
/var/www/html/glvar/rets/vendor/troydavisson/phrets/src/Parsers/GetMetadata/System.php
on line 26
how can i know from this response that i am login in to rets and
i can get any data.
$config = new \PHRETS\Configuration;
$config ->setLoginUrl(***)
->setUsername(***)
->setPassword(***)
->setRetsVersion(***)
->setOption('use_post_method', false)
->setOption('disable_follow_location', false);
empty($user_agent') ? '' : $config->setUserAgent($user_agent);
empty($user_agent_password) ? '' : $config->setUserAgentPassword($user_agent_password);
$rets = new \PHRETS\Session($config);
$connect = $rets->Login();
if ($connect) {
echo " + Connected\n\n";
return $connect;
} else {
echo" + NotConnected\n\n";
}
Here is an ever better way to make sure.. add the code below you $connect and you should get something like the below.. and any response not an error should indicate a connection and show you what was returned..
$connect = $rets->Login();
print "<pre>";
print_r($connect);
print "</pre>";
This will be returned or some thing similar if you are connected..
PHRETS\Models\Bulletin Object
array {
[body:protected] =>
}
Watch out on the above answer.. I ran it on a live RETS feed and it stopped my program in its tracks.. and printed + Connected... I removed the return $connect and changed the \n to and it ran fine and printed Connected.. but my point is it may appear to work fine but the program will not go past the connection test... so it killed my program dead in its tracks... not sure why?

Using a variable variable in an object property in PHP

I've set a few variables:
$field = "XYZ";
$block_hi = $field."_hi";
$block_lo = $field."_lo";
Then I have an object with properties that have the name of my above variables:
$obj->XYZ_hi['val'] = "value1";
$obj->XYZ_lo['val'] = "value2";
I thought I could use PHP's variable variables to reference the properties:
print( $obj->${$block_hi}['val'] );
print( $obj->${$block_lo}['val'] );
I expected to get:
value1
value2
However those lines throw errors in apache's error_log:
PHP Fatal error: Cannot access empty property in script.php
This would work, you had the double $$ which wasn't needed in this instance.
$field = "XYZ";
$block_hi = $field."_hi";
$block_lo = $field."_lo";
print($node->{$block_hi}['val']);
print($node->{$block_lo}['val']);

PHP Mongo DB remove stopping proccess with no error

I'm trying to get rid of a document by _id, but the PHP process stops without error, and no error in access.log, and no output if i assign a variable to remove(). Using mongodb:
version v2.4.9
$connection = new MongoClient();
if($connection == NULL) {
return "some msg";
}
$db = $connection->main;
$collection = $db->users;
$document = $collection->findOne(array('email' => $user->email));
if($document == NULL) {
// do some stuff, works fine.
} else {
$id = $document["_id"];
echo "id=".$id // outputs: 5469a22600a8ebe8418b4567
if($document["confirm"] != "true") {
echo "confirmed not true" // outputs fine
$collection->remove(array('_id' => new MongoId($id)), true);
echo "hello!"; // never occurs
}
}
EDIT: I tried this, and no output:
try {
$collection->remove(array('_id' => new MongoId($id)), true);
} catch(Exception $e) {
echo $e->getMessage();
}
EDIT: I found an answer, but I don't understand the answer because every example I've seen includes the true argument. So I won't self answer this question and leave it up to an expert.
This doesn't work:
$collection->remove(array('_id' => new MongoId($id)), true);
This doesn't work:
$collection->remove(array('_id' => new MongoId($id)), false);
This works:
$collection->remove(array('_id' => new MongoId($id)));
I can explain your problem but I cannot explain why you are not seeing errors, there must be something odd in your PHP setup.
Anyway, as to why your boolean only value for the second parameter does not work: it is because the PHP driver expects an array: http://php.net/manual/en/mongocollection.remove.php the examples you worked from were either incredibly old (Since the change happened 1.0.5 http://php.net/manual/en/mongocollection.remove.php#refsect1-mongocollection.remove-changelog) or incorrect.

how to make php Outlook.Application work and send mail?

if (!defined(‘olMailItem’)) define(“olMailItem”,0);
$objApp = new COM(“Outlook.Application”);
$myItem = $objApp->CreateItem(olMailItem);
$myItem->To=’xxxx#xxx.com’;
$myItem->SentOnBehalfOfName = ‘yyy#xxyyx.com’;
$myItem->Subject=”This is a test”;
$myItem->Body=”This is a Body Section now…..!”;
$myItem->Send();
i get this error
Fatal error: Uncaught exception ‘com_exception’ with message ‘ in D:\NotEncrypted\xampp\htdocs\copper\system\modules\projects\index.php on line 11251 ( ! ) com_exception: Error [0x80004004] Operation aborted in D:\NotEncrypted\xampp\htdocs\copper\system\modules\projects\index.php on line 11251
Thanks for the comments and help guys..
Most likely your Outlook Component Service is not running
run
Start -> run -> dcomcnfg.exe
To see if its there
You also need to check your windows Registry if MAPI.Session is available
Start -> Run -> HKEY_CLASSES_ROOT -> Outlook.Application -> MAPI.Session
If you can't find this then use this tutorials
http://www.digiways.com/articles/php/outlook/
Example
set_time_limit(10);
if (! defined ( "olMailItem" ))
{
define ("olMailItem", 0 );
}
try {
$objApp = new COM ( "Outlook.Application" ) or die ( "Cannot Load Outlook.Application" );
$namespace = $objApp->GetNamespace("MAPI"); // or MAPI.Session
$namespace->Logon();
$myItem = $objApp->CreateItem ( olMailItem );
$myItem->To = "xxxx#xxx.com";
$myItem->SentOnBehalfOfName = "yyy#xxyyx.com";
$myItem->Subject = "This is a test";
$myItem->Body = "This is a Body Section now…..!";
$myItem->Send ();
} catch ( Exception $e ) {
var_dump ( $e->getMessage () );
debug_print_backtrace ();
}
I hope it helps
I just found another solution from this page: http://forums.devshed.com/php-development-5/php-com-automating-outlook-46167.html
Basically PHP doesn't have the constants like olMailList, so you have to refer to it by values. So to make your current script work change this line:
$myItem = $objApp->CreateItem(olMailItem);
to:
$myItem = $objApp->CreateItem(0);
That worked just fine for my situation.

Categories