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

Use array flip + array keys to check no duplicate category ID exists #358

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

acidvertigo
Copy link
Contributor

No description provided.

@gadlol
Copy link
Contributor

gadlol commented Jun 11, 2015

I dont think this is good because it breaks code. when you use return statement nothing will be executed after that. So we need $cPath_array so to check later and return the $tmp_array.

Of course, that function can be improved be replacing sizeof (which is an alias of count) with count and change the for loop including $n=count($cPath_array) or even use foreach loop.

@acidvertigo
Copy link
Contributor Author

As this function is called from application top on:

398      $cPath_array = tep_parse_category_path($cPath);
399     $cPath = implode('_', $cPath_array);
400     $current_category_id = $cPath_array[(sizeof($cPath_array)-1)];

and its purpose is only to convert all $cPath elements to integer make sense to me return directly the reworked $cPath array from the function.

@gadlol
Copy link
Contributor

gadlol commented Jun 11, 2015

What about:

// make sure no duplicate category IDs exist which could lock the server in a loop

@acidvertigo
Copy link
Contributor Author

Yes, now I understand you are right.

Just left unchanged previous code and added array unique to this commit that makes the same thing

@acidvertigo acidvertigo changed the title Return directly lambda function instead to assign it to a variable Use aray unique to check no duplicate category ID exists Jun 11, 2015
@acidvertigo
Copy link
Contributor Author

Changed to array flip method as it is faster

@acidvertigo acidvertigo changed the title Use aray unique to check no duplicate category ID exists Use array flip + array keys to check no duplicate category ID exists Jun 11, 2015
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

Successfully merging this pull request may close these issues.

None yet

2 participants