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

TypeError: preg_match(): Argument #2 ($subject) must be of type string, int given with 6.1.0 #786

Open
Universal-Omega opened this issue Feb 13, 2025 · 3 comments

Comments

@Universal-Omega
Copy link

TypeError: preg_match(): Argument #2 ($subject) must be of type string, int given
vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/ObjectConstraint.php:69

This did not happen before 6.1.0.

There is no indication of what (if anything) is actually causing it in our schema etc...

@DannyvdSluijs
Copy link
Collaborator

@Universal-Omega can you provide some reproduction steps? Linking to some parts in a different code base is somewhat helpful but would require a lot of work from us.

Seeing your schema defined as an associative array (something only available in PHP and not part of JSON) seems to be the problem at a first glance, but I havent checked.

@Universal-Omega
Copy link
Author

@Universal-Omega can you provide some reproduction steps? Linking to some parts in a different code base is somewhat helpful but would require a lot of work from us.

Seeing your schema defined as an associative array (something only available in PHP and not part of JSON) seems to be the problem at a first glance, but I havent checked.

There is no change in configuration between updating yet it simply fails when updating from 6.0.0 to 6.1.0

See

@DannyvdSluijs
Copy link
Collaborator

I still suspect the associative array is the issue here. We are slowly bringing this project up to modern standards which includes the "new" PHP features such as native type hinting etc. Which is the case in the 6.1.0 release

The issue seems to be similar to #780 where a call to json_decode was done asking for an associative array. I believe in your case you should adjust SettingsTest::getSchema(): array to become SettingTest::getSchema(): object to have a correct schema for use with this library.

Also note the docs in ./src/Validator.phpL:36 :

Both the php object and the schema are supposed to be a result of a json_decode call.
It is assumed, but not mentioned, you specify associative with the value true or null. In case of the null value you shouldn't provide the JSON_OBJECT_AS_ARRAY flag to ensure an object is returned.

Deep diving into the specific of your case (already doing more than I wanted to) I can see it breaks because the config contains a section with an incomplete list (similar to what is discussed in #784)

'wgRCLinkLimits' => [
		'name' => 'RecentChanges Link Limits',
		'from' => 'mediawiki',
		'global' => true,
		'type' => 'list-multi',
		'options' => [
			'50' => 50,
			'100' => 100,
			'250' => 250,
			'500' => 500,
			'1000' => 1000,
			'1500' => 1500,
			'3000' => 3000,
			'5000' => 5000,
			'10000' => 10000,
		],
		'overridedefault' => [ 50, 100, 250, 500 ],
		'section' => 'recentchanges',
		'help' => 'List changes limits options to list in the Special:Recentchanges and Special:Recentchangeslinked pages.',
		'requires' => [],
	],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants