Skip to content

Add helpers for Zval coercion #341

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Add helpers for Zval coercion #341

wants to merge 1 commit into from

Conversation

joehoyle
Copy link
Collaborator

No description provided.

self.set_string(if val { "1" } else { "0" }, false)?;
return Ok(());
} else if self.is_array() {
self.set_string("Array", false)?;
Copy link
Contributor

@kakserpom kakserpom Jun 20, 2025

Choose a reason for hiding this comment

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

➜  ~ php -r '(string)[];'
PHP Warning:  Array to string conversion in Command line code on line 1

So I'd suggest removing this.

self.set_bool(val != "0" && val != "");
return Ok(());
} else if let Some(val) = self.array() {
self.set_bool(val.len() != 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

.is_empty()

self.set_long(val.parse::<i64>().map_err(|_| Error::ZvalConversion(self.get_type()))?);
return Ok(());
} else if let Some(val) = self.array() {
self.set_long(if val.len() > 0 { 1 } else { 0 });
Copy link
Contributor

Choose a reason for hiding this comment

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

val.is_empty()

self.set_double(val.parse::<f64>().map_err(|_| Error::ZvalConversion(self.get_type()))?);
return Ok(());
} else if let Some(val) = self.array() {
self.set_double(if val.len() > 0 { 1.0 } else { 0.0 });
Copy link
Contributor

Choose a reason for hiding this comment

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

val.is_empty()

@kakserpom
Copy link
Contributor

@joehoyle @Xenira please take a look and let's merge it. Actually useful stuff.

@Xenira Xenira added the enhancement New feature or request label Jun 20, 2025
@Xenira Xenira force-pushed the coercion-helpers branch 2 times, most recently from bd2ffeb to cfb15cb Compare June 20, 2025 17:06
@Xenira Xenira force-pushed the coercion-helpers branch from cfb15cb to 96c228a Compare June 20, 2025 17:06
@coveralls
Copy link

coveralls commented Jun 20, 2025

Pull Request Test Coverage Report for Build 15784055444

Details

  • 0 of 58 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.3%) to 21.715%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/types/zval.rs 0 58 0.0%
Totals Coverage Status
Change from base Build 15715478100: -0.3%
Covered Lines: 871
Relevant Lines: 4011

💛 - Coveralls

@Xenira Xenira self-assigned this Jun 20, 2025
@Xenira
Copy link
Collaborator

Xenira commented Jul 1, 2025

Had a look at this. Don't know if i like that the Zval is mutated. Maybe a pure version of these functions would be better?

Would also need some tests.

@kakserpom
Copy link
Contributor

Btw, it would be nice to call __to_string() on objects if it's present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants