Opened 15 years ago
Closed 15 years ago
#12362 closed defect (bug) (fixed)
wpdb code improvements
Reported by: | hakre | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Database | Keywords: | |
Focuses: | Cc: |
Description
In Ticket #11644 we started to improve the general code qualitity of wpdb in multiple iterations. We continue here to not clutter the main ticket up any longer.
Attachments (2)
Change History (11)
#2
in reply to:
↑ 1
;
follow-up:
↓ 5
@
15 years ago
Replying to hakre:
__destruct()
return value (should be void, is true)
Doesn't really matter though.
- in the variable definitions, the meta tables sometimes precede their main table.
Sorted by names (which means "commentmeta" comes before "comments"), but I pushed multisite to the end. I think we're good.
- I'm not sure wether unsetting members of an array while iterating it is save with all the PHP version we aim to unset( $tables[ $k ] );.
This should be no problem as-is.
- you've set access to wpdb::$blogid to public.
We use it publicly during the MS loading process. I don't think it's necessary to create setters.
- you skip the note about the problem of registering the wpdb instance with the register shutdown function call prevents it from unloading as expected. What's the problem with leaving a note there? Same for the hints given in wpdb::desctruct(). I found those thoughtfull so we at least have the discrepancies documented.
Not sure I really follow or see the need. We register it for PHP4, I imagine. No reason to document this.
- QUESTION: What's the problem with the scope 'now+old'? I mean there are at least two points in wpdb that will benefit from it.
It's bulky and less clear at what is going on. The alternative, array_merge() on this->tables(blog) and this->tables(old) before looping through, seems unnecessary and also less clear at what is going on. (It's also slower, technically.) Currently it is very clear that we're setting up global tables, then blog tables, then the old tables.
- What's the problem with listing the scope values for table inside the docblock.
We can move it into the docblock.
- wpdb::tables() did not return an array as specified for certain scope values (the undefined ones were forgotten). Patched, will prevent notices/warnings inside the function as well.
Ok, I think we can just add default: return array();
. It only accesses private properties otherwise.
- There is no need to cast an array as array. wpdb::tables() always returns an array, you know that - well okay, not it is.
Sure, we can pull those out.
- Since you did not want to have the merge inside wpdb::tables() (for a reason I do not understand), array_merge still actually works. I prefer to encapsulate that inside tables(), really.
Ok, we don't have any merges outside of wpdb::tables() (see point 6).
- All parameters in tables() are optional.
Ok.
- Scopes can be sorted by alphabet in the switch construct in wpdb::table()
Sure.
- @uses does not fit here, please use @see as already suggested in wpdb::_weak_escape().
Ok.
- for the same class you do not need to prefix wpdb:: for @see and @uses.
Sounds about right.
- Normally alignment is missing in core code, so with these iteration I removed those where I saw them.
Sure.
- If in for single quotes on 'foo', should be in for single quotes on 'SELECT... as well, right?
I would rather not put queries in single quotes, because when a plugin author does that and uses a $wpdb->{table} reference, it doesn't work.
- There is a problem with the preg_replace call in wpdb::prepare() reported on another ticket. I suggest to keep the old behaviour.
- Since when is $this always a reference? Since the beginning or has that changed later?
From the PHP 4 manual: "In PHP4, it was necessary to use a reference to create a callback that points to the actual object, and not a copy of it."
- I did not care about error_log now. I'll do that later. I saw you changed something there, my Idea was to check against the base reference. I suggest to keep that the old code until we have fully clarified that to not break behaviour.
I went over the logic step by step -- my head hurt when I was done, as did westi's -- and I'm pretty sure I cleaned it up while keeping the same behavior.
- It's toally clear that some queries are made prior to load the plugin API. No need to comment, right?
It's clear to you and me, but not to a run-of-the-mill plugin author. We only check whether the plugin API is loaded four times total.
- INFO: wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ) ) was the original example.
I know, I decided to change it to clarify how field types are handled.
- INFO: I still think that constants are normally written uppercase, but I dropped that for this patch to reduce the FUZZ. This needs to be clarified elsewere anyway I assume.
Across core we consistently use true|false|null, not TRUE|FALSE|NULL, especially in inline docs. It reads better anyway.
- There still was a parameter documented that does not exists in wpdb::has_cap(), you've forgotten a line to remove or was that by intention?
Ok, we can remove.
- You made a mistake in changes applied to wpdb::get_caller(), $caller is not filled with values any longer. A line was missing. You can expand it if you like using a temporary variable like $function, but I just patched it.
Looks like I fudged the merge there. Will fix.
- Additionally I moved the join next to return (as always suggested) in wpdb::get_caller().
See point 24.
- Another parameter that does not exists documented in wpdb::db_version() (see 23.)
Ok.
- QUESTION: Include files to not need control characters after the closing ?> at the end, right?
Pretty sure the correct way is the way it is. (We see editors trying to munge the end-of-file line endings all the time, hence why it's in the patch.)
#4
@
15 years ago
Another patch now containing the missing version numbers. This time w/o a list, should be pretty straight-forward to apply. After this is comitted I'll create a last list as summary so unfixed stuff / related tickets won't get lost documentation wise.
#5
in reply to:
↑ 2
@
15 years ago
- QUESTION: Include files to not need control characters after the closing ?> at the end, right?
Pretty sure the correct way is the way it is. (We see editors trying to munge the end-of-file line endings all the time, hence why it's in the patch.)
When necessary:
return; ?>
I never leave PHP tags open.
#6
@
15 years ago
This looks good, though we need to leave $blog_id == 0 there. Thanks a lot for the version numbers, I know how annoying those are to do.
The title's fine, though I don't really need the self aggrandizing. Anyway, I'm uploading your most recent patch. Here is your most recent comment:
Thanks for the feedback. For the version number lookup, that's a job I'll do, no need for you to care. I thought for the same for sorting it, I just wanted to tell you about the Idea. But that's fine anyway now, so I do not need to do it.
Here is a new numbered list, some older unfixed are still on it, just ignore if you do not want to care, I keep them for reference. There are three or four more major points left over, for other just give me a hint what you prefer, sometimes I asked questions, would be great if you can answer them so I know better for upcomming patches we do together.