Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Ability to remove key during merge #6899

Conversation

snapshotpl
Copy link
Contributor

Abilty to remove key using ArrayUtils::merge

@Pittiplatsch
Copy link

Might me a more elegant solution for #3823 / #4505.


namespace Zend\Stdlib;

class ArrayUtilsRemoveKey
Copy link
Member

Choose a reason for hiding this comment

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

I'd say final

@Ocramius
Copy link
Member

Agree with @Pittiplatsch here, this is exactly how a marker value should be used IMO.

if (array_key_exists($key, $a)) {
if (is_int($key) && !$preserveNumericKeys) {
if ($isRemove) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd duplicate the check instead of having an assignment in here (code is very performance sensitive)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking instanceof will be call always, so I don't want to duplicate it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I'm just suggesting a duplication here.

@weierophinney
Copy link
Member

Question: how would this work if the merged configuration is cached and serialized (not uncommon with solutions like EdpSuperluminal)?

if (array_key_exists($key, $a)) {
if (is_int($key) && !$preserveNumericKeys) {
if ($isRemove) {

Choose a reason for hiding this comment

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

I think the $isRemove test should be placed as late as possible, absolutely AFTER is_int and is_array tests, as $isRemove is the most unlikely case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if I want to remove key which is an int?

Choose a reason for hiding this comment

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

You're right. Though I wonder if there is a good solution for avoiding the instanceof check for as much as possible cases...

Copy link
Member

Choose a reason for hiding this comment

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

The instanceof check is the least impacting here

@snapshotpl
Copy link
Contributor Author

@weierophinney After merge array doesn't have this object. So we will serialize "standard" array

@snapshotpl
Copy link
Contributor Author

@Pittiplatsch look at fixed #6903

@Ocramius
Copy link
Member

@snapshotpl still thinking a bit about this one, but I think it's ok to go. Do you think that you can update relevant documentation bits?

@snapshotpl
Copy link
Contributor Author

@Ocramius I will try.

@snapshotpl
Copy link
Contributor Author

@Ocramius Where I should put docs for that?

@Ocramius
Copy link
Member

Interestingly, we don't have a chapter in the docs for the ArrayUtils :-\

It should be somewhere near http://framework.zend.com/manual/2.3/en/modules/zend.stdlib.hydrator.html (PR should go to https://github.com/zendframework/zf2-documentation)

@froschdesign
Copy link
Member

@Ocramius
We have already an issue for Zend\Stdlib: zendframework/zf2-documentation#827

@Ocramius
Copy link
Member

@francisbesset thanks for digging it out!

@Ocramius
Copy link
Member

Ocramius commented Dec 6, 2014

@snapshotpl merged, thanks!

develop: 15437d6

@Ocramius Ocramius closed this Dec 6, 2014
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
@snapshotpl snapshotpl changed the title Abilty to remove key during merge Ability to remove key during merge Aug 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants