The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Is there a reason for the order of arguments in findById() - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Off-topic Discussions (https://userspice.com/forums/forumdisplay.php?fid=10)
+--- Thread: Is there a reason for the order of arguments in findById() (/showthread.php?tid=254)



Is there a reason for the order of arguments in findById() - plb - 09-11-2016

I think every single function in DB.php has the first argument as $table ... except findById().

Is there a reason for this? Maybe if I had the reason for it in my mind I would make the mistake less often...


Is there a reason for the order of arguments in findById() - mudmin - 09-11-2016

The function pretty much always needs to know what table to look in. We could make a searchDB function or something that would search the whole db.

What do you see as the downside with this?



Is there a reason for the order of arguments in findById() - plb - 09-22-2016

Sorry, I wasn't clear. My concern wasn't that every function has table as the first argument - my concern is that findById doesn't. It's the inconsistency in the order of arguments that I'm asking about.


Is there a reason for the order of arguments in findById() - brian - 09-22-2016

@mudmin will definitely need to answer that one...I got nothing except agreement with you.

What do you think a solution would be? What are your thoughts on swapping the arguments in US5 for example.




Is there a reason for the order of arguments in findById() - mudmin - 09-22-2016

I was going to make up a more educated sounding answer, but that method was actually the first method I ever wrote on my own. I used something similar in a procedural php class that I took on Udemy when I first started coding. I thought it would be a nice feature to have.

The method is not actually used anywhere in the UserSpice code. I didn't notice that until after I pushed 4.0 and got a few thousand downloads. I thought about changing it, but then if anyone implemented it, it would break their code. I'd kind of like to flip it for 5.0 and just document the change.


Is there a reason for the order of arguments in findById() - brian - 09-22-2016

@mudmin good answer Big Grin


Is there a reason for the order of arguments in findById() - mudmin - 09-22-2016

Try replacing your us_helpers.php file with this one

http://pastebin.com/J4wnSXfz

And see if it acts like you're thinking it should. In that case, if you don't have a page in the db, it will add it instead of tossing an error. If it can't add it, THEN it will toss the error. There could be bugs, but it's worth a shot. If it doesn't work, you can just replace it with the original.


Is there a reason for the order of arguments in findById() - brian - 09-23-2016

I think you got the wrong thread on this one @mudmin...


Is there a reason for the order of arguments in findById() - mudmin - 09-23-2016

Ooops. Thanks.