Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update class-wp-sqlite-translator.php #40

Closed
wants to merge 1 commit into from
Closed

Update class-wp-sqlite-translator.php #40

wants to merge 1 commit into from

Conversation

lucazdj
Copy link

@lucazdj lucazdj commented Jun 12, 2023

Fixing message error in diagnostics page

Fixing message error in diagnostics page
@eliot-akira
Copy link

eliot-akira commented Jun 20, 2023

I believe this pull request is meant to solve #37, where a fatal error is thrown due to this line.

-$table_name = property_exists( $table, 'Name' ) ? $table->Name : $table->table_name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
+$table_name = is_object( $table ) && property_exists( $table, 'Name' ) ? $table->Name : $table->table_name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

However, adding the check is_object( $table ) is not enough to solve the issue completely because the error message is:

Uncaught TypeError: property_exists():
Argument #1 ($object_or_class) must be of type object|string, array given

It means the variable $table is an array for some reason. In the changed line, if the variable is not an object, the condition tries to access $table->table_name which will throw another type error.

I think the real solution to find out why $table is not an object as expected, somewhere earlier in the error stack trace posted in that issue #37 (comment).

Otherwise, as a temporary solution, the array_filter callback can return false for this exception at the top of the function.

if ( ! is_object( $table ) ) return false;

@@ -2424,7 +2424,7 @@ private function strip_sqlite_system_tables( $tables ) {
array_filter(
$tables,
function ( $table ) {
$table_name = property_exists( $table, 'Name' ) ? $table->Name : $table->table_name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$table_name = is_object( $table ) && property_exists( $table, 'Name' ) ? $table->Name : $table->table_name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I don't think this would actually fix the issue...
if it's not an object, it will try to get $table->table_name which will again error.

Perhaps we should just add an additional condition above this line?
Something like this:

if ( ! is_object( $table ) ) {
	return false;
}

@aristath
Copy link
Member

Closing this one as a fix has already been committed for it in 0753b7c a couple of weeks ago 👍

@aristath aristath closed this Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants