php 5.3 Fatal error Class DateTimeZone not found [duplicate] - php

This question already has answers here:
Problems with PHP namespaces and built-in classes, how to fix?
(3 answers)
Closed 7 years ago.
I tried, to run the following code, on PHP v5.3.13, but still getting the class not found error:
$tZone = new DateTimeZone("Europe/Amsterdam");
How can I use DateTimeZone on 5.3.13?

Try this:
$tZone = new \DateTimeZone("Europe/Amsterdam");

Related

How to declare a class dynamically with a variable in php [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
instantiate a class from a variable in PHP?
(5 answers)
dynamic class names in php
(7 answers)
Closed 2 years ago.
I am trying to make a small script that will load php files and then initiate classes automatically. I am trying to do it like this,
$className = ucfirst($folderName).'()';
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor\$className );
//HERE I AM GETTING ERROR BECAUSE OF THE $class VARIABLE USED.
The error I get:
Parse error: syntax error, unexpected '$className' (T_VARIABLE), expecting identifier (T_STRING)
How can I get ride of the error and initiate the class?

PHP syntax - what's this? [duplicate]

This question already has answers here:
Colon after method declaration?
(2 answers)
Closed 4 years ago.
It's almost impossible for me to search for an answer to this as I don't know what this syntax is called.
I have a server running a relatively old version of PHP (5.5.38) and I'm getting parse errors when I run a file that has the following:
public function foo(): array
{
...specifically the : array suffix.
Can anyone tell me what this syntax is called (so I can research further) and which PHP version introduced it?
This was added in PHP 7, they're called return type declarations.
http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration

Class 'MongoDB\BSON\Regex' not found [duplicate]

This question already has an answer here:
How to have eclipse resolve php classes in MongoDB\BSON namespace?
(1 answer)
Closed 2 years ago.
I trying example from php.net: -http://php.net/manual/en/class.mongodb-bson-regex.php
when performing a code below in php
$regex = new MongoDB\BSON\Regex ( '^Al');
$cursor = $collection->find(array('name' => $regex));
//iterate through the cursor
then php show me error Class 'MongoDB\BSON\Regex' not found
please help me how can i solve this query
You may find that only Eclipse is marking it as a problem, but when you run it on the web server it is fine.
If this is the case then your answer is here:
How to have eclipse resolve php classes in MongoDB\BSON namespace?

php Fatal error: Can't use function return value in write context in functions.php [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 6 years ago.
getting this php fatal error on this line when try apply theme
case('homeimage_texts'):
if(!empty(Params::getParam('homeimage'))){
foreach(Params::getParam('homeimage',false,false,false) as $key => $value){
osc_set_preference($key,trim($value),'osclasswizards_theme');
}
}
osc_add_flash_ok_message(__('Banner settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/'.OSCLASSWIZARDS_THEME_FOLDER.'/admin/settings.php#banner'));
break;
It looks like a PHP version issue. I you are using PHP 5.3 or below you may get this error message.

PHP Fatal error: Can't use method return value in write context [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 7 years ago.
if (isset( $xml->xpath('/lfm/artist/image[#size="extralarge"]')[0])) {
PHP Version 5.3 in use (was 5.7 until server dude switched it to 5.3).
On the line at the top we're getting this error:
PHP Fatal error: Can't use method return value in write context
I've read a few articles but nothing obvious springs to mind - might be a case of not seeing the wood through the trees.
Any advice on how to get rid of the error other than switching back to 5.7?
For compatibility with PHP < 5.4, update your code as follows:
$elements = $xml->xpath('/lfm/artist/image[#size="extralarge"]');
if (isset($elements[0])) {
Take a look at https://wiki.php.net/rfc/functionarraydereferencing if you're interested in learning more.

Categories