« first day (662 days earlier)      last day (4272 days later) » 

user895378
6:00 PM
@Chris I don't think it's the worst thing you could do, but I see no reason not to inject it instead :)
 
user895378
Your API is more transparent if it's injected.
 
@rdlowrey lol
 
The only reason I could give for trait-based inheritance of the functionality is to avoid the need to repeat the "addListener" method in order to publicly expose the mediator and allow external attachment. I suppose one could inject the mediator and use a trait only for the exposed public method....
Still trying to justify the existence of traits, and failing. Hmm.
 
hey guys
what do you think about this query? anything wrong syntax? it's for MySQL
SELECT id,
GROUP BY Sum(OrderItems.price + Orders.shipping_amount)
FROM Orders
INNER JOIN Orders
ON Orders.id=OrderItems.order_id
WHERE date < 'June 1, 2003'
ORDER BY Orders.id DESC
 
user895378
@LeviMorrison Are you waiting for me to start talking about phpunit mocks or are you going to ask questions?
 
6:06 PM
@rdlowrey I'll ask questions, yeah. Doing something else at this very moment.
 
user895378
@LeviMorrison oh okay, just making sure :)
 
I guess I do have one question: can I mock something to make it throw an exception/
 
@hanleyhansen Yes, you're joining the wrong table
 
can you elaborate please
 
And using GROUP_BY incorrectly
 
6:08 PM
better?
SELECT id
FROM Orders
INNER JOIN Orders
ON Orders.id=OrderItems.order_id
WHERE date < 'June 1, 2003'
GROUP BY OrderItems.price , Orders.shipping_amount
ORDER BY Orders.id DESC
 
No
SELECT
	id
FROM
	Orders
INNER JOIN
	OrderItems ON
		Orders.id=OrderItems.order_id
WHERE
	Orders.date < 'June 1, 2003'
GROUP BY
	Sum(OrderItems.price + Orders.shipping_amount)
ORDER BY
	Orders.id DESC
id columns are usually not the best choice for ordering, though, date would probably be more appropriate
 
I always get confused with the joins
 
@SomeKittens can you spot the differences?
 
@hanleyhansen dev.mysql.com/doc/refman/5.0/en/join.html -- your FROM tables are already in the query, your INNER JOIN should then list which table to add in, then ON specifies the field
Err, you probably also want to explicitly specify which id to get... SELECT OrderItems.id... or SELECT Orders.id...
 
@webarto the # and #s. One doesn't need a diff for that. What do they do? (raw string?)
wait, you also escaped the /
 
user895378
6:14 PM
@LeviMorrison oh yeah, no problem:
 
@Chris cool thanks.
@Chris will do.
 
@hanleyhansen Also, that GROUP BY is no good. I just noticed, but I can't figure out where you're going with that
 
# is a delimiter php.net/manual/en/regexp.reference.delimiters.php, you need to start with one, and end with one, after last one comes pattern modifiers, 's' means match newlines also (otherwise it will stop on first newline)... use delimiter you don't use in regexp, e.g. if you use # you don't need to escape / (because you are not using it as a delim). addedbytes.com/cheat-sheets/download/… @SomeKittens
 
Hey guys
 
@rdlowrey Can you mock an interface?
 
user895378
6:18 PM
@LeviMorrison YES!
 
user895378
$mock = $this->getMock(
    'Namespace\\MyClass', // class to mock
    array('methodToMakeThrowException'), // only mock this one method, leave the others as-is
    array('ctorArg1', 'ctorArg2') // optional constructor arguments if your class requires them
);

$mock->expects($this->once()) // requires method is called exactly once
     ->method('methodToMakeThrowException') // which mocked method to set constraints on
     ->with('expectedArg1', 'expectedArg2') // optional constraints
     ->will($this->throwException(new Exception));
 
@hanleyhansen This? pastebin.com/qeqNf9JH
 
@webarto Awesome, thanks for the full explanation
 
back
 
user895378
@LeviMorrison see above for mocking a class method to get it to throw an exception
 
6:19 PM
@Chris that makes a lot of sense. thanks.
 
@rdlowrey Thanks.
 
user895378
If you specify an interface as the mock class name it will just automatically mock all the methods and make them return null
 
user895378
So if you want custom behavior on an interface mock you have to add it yourself like I did above for the one method.
 
Why this:

(Sum(OrderItems.price) + SUM(Orders.shipping_amount))

Instead of this:

Sum(OrderItems.price + Orders.shipping_amount)
 
6:22 PM
@hanleyhansen No reason, preference I guess :)
 
@Chris Ok so either one is valid?
 
Either one is valid, but you'd want to test to be sure it means what you think it means.
 
ok so here's my final query:

SELECT
Orders.id,
SUM(OrderItems.price + Orders.shipping_amount) AS amount
FROM
Orders
LEFT OrderItems ON
Orders.id=OrderItems.order_id
WHERE
Orders.date < '2003-06-01'
GROUP BY
Orders.id
ORDER BY
Orders.id DESC
 
You're better off being explicit -- if you explicitly define what you want, you'll get exactly that back. Sum(OrderItems.price + Orders.shipping_amount) might result in the same number, but I can think of why it wouldn't.
 
@Chris i'm curious. tell me.
btw how can i be sure it works in mysql as opposed to ms sql?
 
6:25 PM
Test
 
only way?
in case anyone cares
 
To be sure? Yes, doing it is the only way to be sure. If you know and can write valid SQL, you're 90% of the way there
Usually, if you're writing SQL that means you have a database to test with
I would venture to claim that only a crazy person writes SQL and blithely assumes it works (or relies on some kind of tool or validator) without actually testing it on a database.
 
@rdlowrey What is this $this->once() business?
Oh wait, I think I just got it.
If you call it more than once, it will error?
 
anything other than once, it will error
 
$this->once(); /* should work */ $this->once(); /* should fail */
 
user895378
6:30 PM
@LeviMorrison yes.
 
user895378
You could also do:
 
user895378
$this->any() // I don't care how many times the method is called
 
user895378
$this->exactly(5) // I expect this method to be called five times
 
user895378
You can get crazy with logical bitwise constraints as well ... like ...
 
user895378
->with($this->logicalOr('expectedArg1', 'expectedArg2'))
 
6:33 PM
Let's say I need to make a callable and just need to make sure it is called. How would I do that?
 
@stack98 GLOBAL IS BAD! — SomeKittens 24 secs ago
 
user895378
@LeviMorrison Is it a callable object that gets injected into the class under test?
 
@rdlowrey It's a listener :)
It could be whatever.
I just need to make sure the event was called, basically.
 
user895378
In that case ...
 
user895378
Somewhere in the test file add an interface like this:
 
user895378
6:36 PM
interface ListenerStub {
    function __invoke();
}
 
user895378
and then do:
 
user895378
$listenerMock = $this->getMock('ListenerStub');
$listenerMock->expects($this->once())
             ->method('__invoke');
 
user895378
And inject the $listenerMock into the test class
 
Gotcha.
 
6:38 PM
@PeeHaa Don't lie.
I will never give up on them :P
 
> The reason it is more secure to store it into a file is that then you have a record of what was run;
w.t.f.
0
A: create and include a file insetead of eval in php, is it good?

Theodore R. SmithIf you have to create code dynamically, it is always more efficient and usually more secure to dump the output into a file and then include it. Then you only have to do this once per piece of code and it allows for opcodes caching (via APC and the like) and more efficient preprocessing by the Zen...

 
user895378
RepWhoring in full effect!
 
user895378
3
A: PHP referring array item without extra line

rdlowreyIt's called array dereferencing. And it's available as of PHP 5.4. If you want it, upgrade your PHP.

 
@PeeHaa You do realize that that's the phpexperts.pro guy? You know, that one from reddit? With his courses.
 
@NikiC holy shit. nope I didn't
@NikiC Now I'm not giving up on this one
:P
 
6:41 PM
gist: ROT13 in js, 2012-08-08 18:35:25Z
["string"].map(function(a){return(a=(a)?a:this).split("").map(function(b){if(!b.match(/[A-Za-z]/)){return b}c=b.charCodeAt(0)>=96;k=(b.toLowerCase().charCodeAt(0)-96+12)%26+1;return String.fromCharCode(k+(c?96:64))}).join("")}).join("");
 
Is that that theadore guy? @NikiC
 
Lbh thlf unir sha jvgu guvf!
 
@PeeHaa hm?
@PeeHaa Yes
Click his profile ;)
 
I wasn't here last week for my friday js fun ( so you get it mid week this week. )
 
@rdlowrey I'm getting 'No method matcher is set' but the stack trace isn't helpful.
 
6:42 PM
hey fellas
 
user895378
@LeviMorrison Not sure, I'd need to see the code
 
@ircmaxell I decided that I won't make the random string proposal. I'm not qualified to do it.
 
When I jump out of a plane without a parachute it is more safe because I know I am jumping without a parachute. Which is way more safe the jumping out of a plane and only while jumping I realize my chute doesn't work. I have news for you. In both situations it probably won't end well. — PeeHaa 29 secs ago
 
@rdlowrey I think I'll try to muck my way through this one.
 
user895378
@LeviMorrison I think that usually happens if you don't have a ->method('someMethod') but I'm not sure.
 
6:44 PM
@PeeHaa It's called bansai skydiving. They throw the parachute after you.
 
@NikiC :P
 
The sport of banzai skydiving involves throwing a parachute out of a plane and then jumping after it, the aim being to catch up with it, strap it on and deploy the parachute before hitting the ground. The longest time ever recorded is three minutes. Craig Glenday, editor of Guinness World Records, has used Banzai Skydiving as an extreme example of the book's policy to keep records for record categories in which only the life of the participant would be put at risk. As a counter-example, he indicates that record attempts that might put another person or animal at risk, such as "fattest pet...
 
@rdlowrey Yep, that was it.
 
Or rather, they throw it out first ^^
 
user895378
If you don't know how to use your camera's autofocus, I don't want you teaching me PHP.
 
6:45 PM
@NikiC wow :)
 
user895378
@NikiC That's pretty F-ing serious. Wow.
 
Probably still safer than base jumping ;)
 
To all the downvoters, this is a very clear and thought out question. Why all the hate? Are you in some sort of anti-eval() frenzy? — Theodore R. Smith 5 mins ago
 
anyone know what permissions should be for the php temp dir?
 
Shouldn't we just close the question for the better of the community?
 
6:49 PM
"BASE jumping as of 2002 has an overall fatality rate estimated at about one fatality per sixty participants." hm...
 
@NikiC 1 out of 6 eeeek
Better stay inside and keep coding
 
sixty ;)
 
oops looool
 
With one in six noone would do it :D
 
@NikiC I bet people would still do it :)
LIve life on the edge man ;)
 
6:53 PM
the permissions of my tmp folder got all crazy after switching to mamp pro so i just made it 777, is that ok?
 
> Perrine Bridge in Twin Falls, Idaho, is an example of a man-made structure in the United States where BASE jumping is allowed year-round without a permit.
Why Idaho, I didn't know you were so exciting!
 
@rdlowrey Success at mocking! Thank you :)
 
user895378
@LeviMorrison no problem. I don't have all the answers, but often if you have a question about it I can help.
 
@NikiC :-( I guess I'll have to
 
6:56 PM
@ircmaxell Yes, sorry.
I feel like I don't have the necessary background knowledge for it
 
I don't mind doing it...
 
user895378
@LeviMorrison Test mocking really drives home how awesome it is to write clean code, typehint non-concrete interfaces and inject your dependencies. It makes proving that your code works as easy as it can be. Congratulations :)
 
@PeeHaa dafuq did I just read... "generated code is faster"...
 
please just close this question: stackoverflow.com/questions/11870843/…
 
@ircmaxell Do you have a link to any canonical SO question/answer along the lines of "why people should use crypt for hashes" ?
 
7:05 PM
@PeeHaa smarty templates are eval'd? O.o
 
i wouldn't be surprised
btw, hi everyone
 
@webarto :P You shouldn't know that in the first place :)
 
If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf, BDFL of PHP
 
Hi!
 
@tereško Alo
 
@Chris I admire your persistence :)
 
@tereško herro
 
@tereško out of curiosity: What logic have you had [needed to] appear in a domain object? I never seem to need any logic there, just plain data
 
@tereško ola
 
@orourkek validation of data , for example
 
7:21 PM
that makes sense, thanks
 
ok. i have an input field. where the user can type either text ir their urls.. but in the php validation for the input. how do i differentiate which of the input string is text and which is url?
 
@Truth I don't think the question needs to be closed, and I thought you said so too. The guy wants to argue with his answerers, and that's ridiculous, but the question itself is valid.
 
I wanted to say to him "this is not Facebook"
 
Yeah, I looked at it -- looks like a valid question but his attitude toward any answer that went against his pre-conceived ideals and wants make that question no longer valid. It's pretty much nothing more than arguing back and forth at this point which isn't something we need future visitors to really see no matter how valid the original question once was
 
- Removed Zend\Registry; without the singleton nature, it was confusing
and no longer relevant.
Wow, have they actually learned something?
 
7:32 PM
They removed it because it was confusing, not because it is bad practice. I doubt the learned anything ;) @GordonM
 
was dat registry thing meant to be used in Controllers, Models or both?
 
@PeeHaa And the next thing i read prompted a . - Select-style elements now have options populated as value => label pairs instead of label => value pairs. This is done to ensure that option values are unique.
So they went for the non-intuitive option just so they wouldn't have to do if ($vals !== array_unique ($vals))
 
Also done to prevent confusion I guess :P
 
damn I'm confused now
 
:P
 
7:36 PM
@Justin your site is down?
 
pcworld.com/article/237167/… force of retards in the comments is strong
 
@webarto hahaha
 
"I am enjoying Instagram, my Droid Razar just has a larger screen than the Iphone and other androids."
"this is freaking stupid and didnt answer my question"
 
pls tell me nah
 
I just hate seeing Stackoverflow turning into something like this...
 
7:45 PM
how to differentiate betwen text and url
 
should I laugh? :)
what do you mean? @blackbee
 
@webarto You shall.
 
@NikiC I'm laughing T_T
 
i mean there is a single input field.... any user can enter either a (ok in terms of facebbok) a status update or an url.. now how do i validate wether the url enterd is valid or not
 
user895378
good god the passed-by-reference parameters in some native php functions drive me nuts sometimes.
 
user895378
7:49 PM
stupid stream_socket_client parameters make it a real PITA to mock if you want meaningful error messages
 
@PeeHaa yeah it's down -- I old server caught on fire and I haven't put the new one up yet
Maybe i'll just use my work server instead of putting mine up.... Save me the headache of having to admin a 2nd server..
 
@blackbee ideone.com/9Xchx something like should work, you also remove text etc... just leave bare link... although regex for this is complicated and often there is no silver bullet...
 
@Justin :)
 
owkayz
 
Cisco is on fire, we don't need no water let the mofo burn :)
 
7:56 PM
Not that it matters at this point anyway -- I've not finished the development of the new site lol... Been TOO busy...
 
This is a question of preference, curious: In an object method where you use a switch to react to a parameter, do you typically add a default clause to catch invalid parameters? I do... and I usually return false from that case. Should I break and return false below the switch instead? I know it doesn't matter programmatically, just wondering on the convention
 
@Justin I know that feeling :)
 
Depends on the use case on that for me.. Sometimes I add a default, othertimes I don't...
Mostly depends on if it's going to be triggered by user or not as to whether i add a default or not...
 
is bullet made of silver? then its worth dying by being shot!!
 
@Chris personally I avoid switches, but I would have avoided it because e.g. I always expect that line before } returns :)
@blackbee YOLO? xD Silver is relatively cheap.
 
7:58 PM
:P
aw. in india its just next to gold........
 
@blackbee I don't have any silver bullets, will death by commuter train suffice? Anything that makes it so I don't have to go home tonight.. ;)
 
user895378
@Chris I don't feel strongly about it, but I put the default behavior inside the default case.
 
	$return = null;
	switch ($condition) {
		... cases ...
		default:
			break;
	}
	if (!$return) return $return;

	// versus

	switch ($condition) {
		... cases ...
		default:
			return null;
	}
 
@blackbee by price or in culture?
 
both
 

« first day (662 days earlier)      last day (4272 days later) »