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

idn_to_ascii() on PHP 7.2 #5300

Closed
ivantcholakov opened this Issue Oct 14, 2017 · 11 comments

Comments

Projects
None yet
7 participants
@ivantcholakov
Contributor

ivantcholakov commented Oct 14, 2017

CodeIgniter 3.1.6, PHP 7.2.0RC3

As of PHP 7.2 the constant INTL_IDNA_VARIANT_2003 is deprecated.
https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003

The function idn_to_ascii() as is currently used throws the warning:

A PHP Error was encountered
Severity: 8192
Message: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated
...

There are three places to be updated:

Email library, the method valid_email()
https://github.com/bcit-ci/CodeIgniter/blob/3.1.6/system/libraries/Email.php#L1035

With the following snippet:

        $this->load->library('email');
        echo $this->email->valid_email('test@Bloß.de') ? 'yes' : 'no';

I tried this modification that seems to me ok:

	public function valid_email($email)
	{
		if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46') && $atpos = strpos($email, '@'))
		{
			$email = self::substr($email, 0, ++$atpos).idn_to_ascii(self::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46);
		}

		return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
	}

The second place that would need a similar modification is CI_Email::valid_email()
https://github.com/bcit-ci/CodeIgniter/blob/3.1.6/system/libraries/Email.php#L1852

And the third pace is CI_Form_validation::valid_email()
https://github.com/bcit-ci/CodeIgniter/blob/3.1.6/system/libraries/Form_validation.php#L1230

narfbg added a commit that referenced this issue Oct 16, 2017

@narfbg narfbg added the Enhancement label Oct 16, 2017

@narfbg narfbg added this to the 3.1.7 milestone Oct 16, 2017

@narfbg

This comment has been minimized.

Show comment
Hide comment
@narfbg

narfbg Oct 16, 2017

Contributor

Thanks, I've pushed a patch for this.

Contributor

narfbg commented Oct 16, 2017

Thanks, I've pushed a patch for this.

@narfbg narfbg closed this Oct 16, 2017

narfbg added a commit that referenced this issue Nov 9, 2017

@udin-ordinary

This comment has been minimized.

Show comment
Hide comment
@udin-ordinary

udin-ordinary Feb 27, 2018

hello all,
for idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated
just add this in system/libraries/form_validation.php in line 1234

	public function valid_email($str)
	{
		if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
		{
			$str = $matches[1].'@'.idn_to_ascii($matches[2],IDNA_NONTRANSITIONAL_TO_ASCII,INTL_IDNA_VARIANT_UTS46);
		}

		return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
	}

correct me any mistake.
its work for me with CI.3.1.7

many thanks,

udin

udin-ordinary commented Feb 27, 2018

hello all,
for idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated
just add this in system/libraries/form_validation.php in line 1234

	public function valid_email($str)
	{
		if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
		{
			$str = $matches[1].'@'.idn_to_ascii($matches[2],IDNA_NONTRANSITIONAL_TO_ASCII,INTL_IDNA_VARIANT_UTS46);
		}

		return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
	}

correct me any mistake.
its work for me with CI.3.1.7

many thanks,

udin

@narfbg

This comment has been minimized.

Show comment
Hide comment
@narfbg

narfbg Feb 28, 2018

Contributor

CI 3.1.7 doesn't have this issue; I don't understand why you're suggesting modifications at all.

Contributor

narfbg commented Feb 28, 2018

CI 3.1.7 doesn't have this issue; I don't understand why you're suggesting modifications at all.

@udin-ordinary

This comment has been minimized.

Show comment
Hide comment
@udin-ordinary

udin-ordinary Mar 1, 2018

dear narfbg,

yes it does...iam facing that problem with CI 3.1.7 with PHP 7.2 on Xampp...so if any others face it that works for me.

many thanks for your reply.

udin-ordinary commented Mar 1, 2018

dear narfbg,

yes it does...iam facing that problem with CI 3.1.7 with PHP 7.2 on Xampp...so if any others face it that works for me.

many thanks for your reply.

@narfbg

This comment has been minimized.

Show comment
Hide comment
@narfbg

narfbg Mar 1, 2018

Contributor

No, it doesn't.

Particularly on PHP 7.2 the only way to trigger that notice is if you have an ICU version lower than 4.6, at which point there's literally nothing you can do about it.

Read more here: https://forum.codeigniter.com/thread-69780.html

Contributor

narfbg commented Mar 1, 2018

No, it doesn't.

Particularly on PHP 7.2 the only way to trigger that notice is if you have an ICU version lower than 4.6, at which point there's literally nothing you can do about it.

Read more here: https://forum.codeigniter.com/thread-69780.html

@datamweb

This comment has been minimized.

Show comment
Hide comment
@datamweb

datamweb Jul 29, 2018

@narfbg
This is also a problem for me.
PHP ver:7.2
CI ver: 1.3.9

datamweb commented Jul 29, 2018

@narfbg
This is also a problem for me.
PHP ver:7.2
CI ver: 1.3.9

@williamabbott

This comment has been minimized.

Show comment
Hide comment
@williamabbott

williamabbott Jul 30, 2018

Same here PHP 7.2 CI 3.1.8

williamabbott commented Jul 30, 2018

Same here PHP 7.2 CI 3.1.8

@vaultdweller123

This comment has been minimized.

Show comment
Hide comment
@vaultdweller123

vaultdweller123 Aug 9, 2018

why is this closed? this is not fixed. i got this error on my server but works on local weird!? fix pls! im not using this CI email validation at moment. id rather override this with my own email php validation or on js. this is no good

vaultdweller123 commented Aug 9, 2018

why is this closed? this is not fixed. i got this error on my server but works on local weird!? fix pls! im not using this CI email validation at moment. id rather override this with my own email php validation or on js. this is no good

@AG0001

This comment has been minimized.

Show comment
Hide comment
@AG0001

AG0001 Sep 12, 2018

Same here PHP 7.2.1 & CI 3.1.8 . "valid_email()" has a serious issue .

AG0001 commented Sep 12, 2018

Same here PHP 7.2.1 & CI 3.1.8 . "valid_email()" has a serious issue .

@vaultdweller123

This comment has been minimized.

Show comment
Hide comment
@vaultdweller123

vaultdweller123 Sep 12, 2018

that shit also error when you use their email library

vaultdweller123 commented Sep 12, 2018

that shit also error when you use their email library

@narfbg

This comment has been minimized.

Show comment
Hide comment
@narfbg

narfbg Sep 13, 2018

Contributor

That shit is the fault of whoever setup your servers with libicu versions from 10 years ago that nobody should be using anymore. And before talking shit, you should at least read the shit that I wrote.

I'll repeat and simplify: this is impossible to fix! Literally. Not possible.

PHP 7.4 will require libicu 50+, at which point you'll be forced to have a proper setup and the error message will go away, but until then - start bothering your server guys, hosting companies, etc. It's their fault.

Contributor

narfbg commented Sep 13, 2018

That shit is the fault of whoever setup your servers with libicu versions from 10 years ago that nobody should be using anymore. And before talking shit, you should at least read the shit that I wrote.

I'll repeat and simplify: this is impossible to fix! Literally. Not possible.

PHP 7.4 will require libicu 50+, at which point you'll be forced to have a proper setup and the error message will go away, but until then - start bothering your server guys, hosting companies, etc. It's their fault.

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