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

How to get original unit? #77

Open
spiroski opened this issue Apr 26, 2018 · 3 comments
Open

How to get original unit? #77

spiroski opened this issue Apr 26, 2018 · 3 comments

Comments

@spiroski
Copy link

How can I get the original unit of an instance?

@triplepoint
Copy link
Member

triplepoint commented Apr 27, 2018

That's a good question; there's currently no way to get just the original unit back out. I think the best you can get is to cast a PhysicalQuantity object to a string, and then break on the space, like so (untested):

$height = new Length(6.16, 'feet');
list($original_value, $original_unit) = explode(' ', (string) $height);
echo $original_unit;  // This is what you're looking for

Please note that this strategy will return the canonical name of the original unit, not the particular alias you might've actually passed into the constructor. So for instance if you created a Mass object with new Mass(2, 'pounds');, the $original_unit value will be lbs.

But it does seem like there should be a more direct way to fetch the original value and the original unit. That's probably worth adding.

Does that help?

@marcortola
Copy link

How about adding a getter method in the AbstractPhysicalQuantity class?

@amenk
Copy link

amenk commented Apr 24, 2019

Same is for originalValue -> currently there are no getters for this. Should we just make a PR?

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

No branches or pull requests

4 participants