After updating PHP 7.4 to PHP 8.1 RC5, PHP has stopped working on my machine and produces following error: PHP Warning: PHP Startup: ^(text/|application/xhtml+xml) (offset=0): unrecognised compile-time option bit(s) in Unknown on line 0 it produces the error even when I ask for php version: OS: Ubuntu 20.04 u…
Annotations: How to specify timestamps in docblocks in php
I have a mehtod that returns timestamps. I want to do something like this: However, I don’t think @return array<int, timestamp> is valid. What is the valid format for specifying timestamps in docblocks? Answer You can use int[], there is no valid value for timestamps. You can however create a Valu…
Cannot Redirect to the correct page using PHP session
In my application I have 4 roles. As per the roles, Users can view their access different pages. Currently I am maintaining 2 different sessions. $_SESSION[‘user_id’] and $_SESSION[‘role_id’]. My problem is, suppose we say the role_id =1 is Admin, role_id=2 is Doctor. If I logout from …
PHP 8.0.12 Error Reporting Not Showing All Errors
I’m trying to move an application to PHP 8 from PHP 7. But whenever there’s an error in my code, only the first error is displayed, even if there’s a fatal error after that first error. error_reporting is set to E_ALL, display_errors and display_startup_errors are on. For example, Only the e…
How to crawl page in PHP?
I get the error: “error code: 1020″. The page I’m trying to crawl for form data is: https://v2.gcchmc.org/medical-status-search/. This is my code: $initial = file_get_contents(‘https://v2.gcchmc.org/medical-status-search/’); $check = preg_replace(‘/.+?input type=”hidd…
Is there a method in PHP to use a varible as all or part of a classname?
Example The goal is to have a dynamic variable which changes the appended string based on folder names found in a directory. Answer It is possible to use PHP to write a file that contains a class definition and then include or require that file. The newly created class could have a name based on a variable. S…
PHP / Javascript AES 128 CFB Encryption / Decryption CryptoJS OpenSSL
Working Decryption in PHP Will output “Decrypted Message” I’m trying to replicate it in Javascript I get an empty response, any help would be appreciated as to where I’ve gone wrong. Thanks Answer CFB is a stream cipher mode, i.e. does not use padding. In a mode with padding, the ciphe…
PHP MySQL Selecting Multiple Tables Based on Column/Row Value
I am just doing some testing with a few tables that I’m trying to relate together, based on the values of my ‘students’ table. Here are the total tables that I have: students TABLE id, name, course_num, msg_num biology TABLE id, details, msg_num chemistry TABLE id, details, msg_num physics T…
Issue regarding text redirect which shouldn’t occur
I have an HTML text field, and a post button, which you click to make a post. Now, to send this post to the database, I made a separate file called post.php to handle the PHP and MySQL code for that, …
Group and sort multiple associative arrays in PHP based on two conditions
I have couple of associative arrays like this I want to get the arrays that have the latest hired year, and also based on the department order. so the department priorities are [‘math’, ‘science’, ‘social’] (ordered based on priority) If only one array has recent years: For…