« first day (1467 days earlier)      last day (3474 days later) » 

4:01 PM
I think that is going to be different in php
 
posted on October 22, 2014 by Anthony Ferrara

I've never been a rock. I'm about as passionate as someone can be when I choose to do something. Unfortunately that means I tend to throw myself (my raw unadulterated self) at my interests. It's just who I am and who I've always been. This has positives and negatives associated with it (especially from a personal perspective). Throwing yourself at a passion has enormous benef

 
Let me see
 
user895378
@ircmaxell oh noes! it's spelled "falter" :)
 
eih
seriously?
wtf
 
user895378
It would totally make sense if it were "faulter," though.
 
4:03 PM
@ircmaxell It's only in the title :P
 
fixed
 
s/only/just
 
and the URL is the only thing that won't change now
 
:D
ok @Fabien doable
 
opt:check_log
args[aid]:6228
args[lid]:48096029
args[oid]:0
args[ref]:
@Fabien it's sends this to some ajax.fly.php and then eval's something to get the link...
 
4:06 PM
Will fix you up later. When I'm finished doing actual work. Unless your life depends on it and it needs to happen NOW!!1111 URGENT!!!111 @Fabien
BTW do I get pirate gold when I do it :P
 
Ah cool thanks guys :) I got as far seeing those calls but the return was some hash looking thing
 
@Fabien It uses it for the next call ;)
 
That's the first-ish call.
 
page -> get hash -> use hash to get url
{insert magic meme}
 
@Fabien ATM
 
4:21 PM
posted on October 22, 2014 by kbironneau

/* by PhilReinking */

 
@RonniSkansing yep
 
user895378
@crypticツ halloween ponies \o/
 
halloween? I just came from the glue factory.
 
Is that some sort of FactoryFactory?
 
gist.github.com/mikedidthis/3a9d017f53e6746489d0 mine was "borrowed" from online, but Mike is making Halloween avatars if anyone is interested. Hurry while supplies last.
 
4:40 PM
@Fabien do you really need it or just for fun?
 
@webarto It's work so I need it but it's not something someone else should spend their time on unless they're interested. :P
 
@ircmaxell (re: blog post) It's not only you. There are other people which are much more emotionally attached to their doings. It's not a bad thing to be emotionally attached, but if one is too much attached, any criticism will be perceived like really destructively meant. You tried to make one point and you made it. That's fine. There are people who really see the constructive part about it. And there are some who just find destructive parts even when there are none. Please, just be yourself.
 
You have to send 2 POST requests in order to get the URL in 3rd. It's not a biggie, I can do it or Pieter, do something more useful :P @Fabien
 
You guys don't have to unless bored :P. I appreciate it but it really is my work :P
 
@bwoebi believe it or not, this doesn't just have to do with my earlier posts
 
4:42 PM
@Fabien devprotalk.com/showpost.php?p=109129&postcount=1 it's fine, that's how I won nice LCD TV.
 
@ircmaxell I assumed that already. But you're really doing well.
 
@webarto heh nice
 
Hi Guys, I am making a blog and Made a Post class. In the class I have an static function that gets all the posts in an associative array for thisplaying at homepage. Then I want to make another function to get just one post. But I don't know if it should return a new static() obj, an obj, or an array
 
@ircmaxell by the way, sometimes one does have to destruct things to construct new things. As much it hurts, it's necessary.
 
@Miguel_Velazkez This Post class, what is it's primary responsibility? To retrieve data from the database? If so, consider a PostRepository that only gets data from the database, and Post Entity which is your actual post.
You build your Entities and return an array of those objects. And you're not using statics.
Then in your repository you can have findAll() and findOneBy('id' => $id) // or something similar
 
user895378
4:47 PM
I need to start writing integration tests that run for a few seconds and verify that memory is not leaking in code intended to run for a long time ...
 
@webarto I'm finishing work for today anyhoo so definitely not rush
 
user895378
@Fabien I'll likely push some things this evening that effect you. No API changes, just internal things. You may want to do a composer update against the current master tomorrow.
 
@ircmaxell The issue is maybe that we only begin complaining when things already are unsalvageable. That we wait until the point we can do all, but destruct.
 
@rdlowrey Cool thanks
 
user895378
> If I start to waver, I just leave. I take some time off. I have done this multiple times, with multiple projects.
 
user895378
4:50 PM
^ @ircmaxell welcome to the club :)
 
user895378
It's terrible but I do it too.
 
If you start to waver, perhaps you're working too hard in the first place? :-) Gotta find your comfortable level you can stay at for the long haul!
 
@ircmaxell Just the example with the cache PSR. First semester 2013 it first went to the public. Now everyone is attached and every tiny criticism is felt like destructively meant.
 
user895378
Yes, but the "working too hard" is a direct result of "wanting to because you're so passionate about something."
 
user895378
You do it because you want to. But it's not healthy.
 
4:52 PM
But you can find somewhere where you can be passionate about what you do, but where the workload isn't such that you can be worn out
I think it's about finding the right company that can give you that, as well as somewhere that can give you good work/life balance - where you're not going home and thinking about work all the time
 
user895378
Well I don't think it has so much to do with where you work. It has to do with you personally regulating how much time you spend on something.
 
user895378
I'm not talking about work I have to do because someone tells me to do it.
 
@rdlowrey I gave those anti-accessor articles a read. If you have an ecommerce store with an article entity (think name, description, price etc) that you want to display in the store, how would you display that data without using getters (or something that has a different name but does the same)?
 
If it's work you choose to do then surely, as intelligent person, you can go "right, logically, I am going to stop now else risk burning out"
 
user895378
@Patrick I'm not saying they're always bad. It's just that most of the time most developers write bad code and building getters/setters into the language only makes bad code easier and more frequent.
 
4:54 PM
I guess that's the self regulation you talk about. Personally, I'm fine with that. Different level of passion I guess :P
 
user895378
@Jimbo lol, clearly you've never OCD.
 
0Cd
:P
 
user895378
It's a personality flaw, for sure (I have it ... well, self-diagnosed, anyway).
 
	reckistring * var1;
#if PHP_VERSION_ID >= 70000
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &var1) == FAILURE) {
		return;
	}
#else
	char *var1_val;
	int var1_len;
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &var1_val, &var1_len) == FAILURE) {
		return;
	}
	var1 = recki_string_init(var1_val, (size_t) var1_len, 0);
#endif
	reckiretval = recki_if_test(var1,  &validReturn);
	if (validReturn != SUCCESS) {
		return;
	}
 
\o/ I have to crawl shit for a new project
 
4:56 PM
@rdlowrey I see. With that I can agree. It's just that some of the arguments were about totally abandoning them which I don't see as very reasonable. But not using them for everything, definitely.
 
@PeeHaa Took a job with Mike Rowe, did we?
 
lol
 
user895378
@Patrick We're totally on the same page then.
 
user895378
@Machavity I see what you did there.
 
@rdlowrey Only on video games - achievements actually lol
 
4:57 PM
@Jimbo :D thanks! I did all this with just functions before but I want to practice with OOP
So this is what I have at the moment.
So I will have a PostRepository class to get posts and the Post Class to insert posts?
Or could I call a PostRepository getPost() and it would return an obj of the Post Class?
 
@Miguel_Velazkez Some people advocate having a PostRepository::save(Post $post) method in there
 
@Miguel_Velazkez No need to check those thing in the ctor
 
@Miguel_Velazkez eww static...
 
ow didn't scroll far enough
 
4:59 PM
$db = new Db;
$db->query("SELECT id, title, description, body, slug FROM posts WHERE slug = '$slug' LIMIT 1");
$result = $db->getResult();
the magic is strong in this one
 
{insert permalink of the consequences of sharing code in here}
;-)
 
@Miguel_Velazkez I think you could benefit from giving those principles a read :) en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29
 
@Miguel_Velazkez Sorry, I'm just going to go get dinner, ask someone else to help you with that code :-) Quick tips: Don't use mysql_* methods. Pass in your DB via Dependency Injection. Don't allow nulls on your posts, force a valid Post to have those parameters (not null). Have the following objects:Post, PostRepository, PostValidator, PostFormatter. Have an interface for the formatter so you can format it differently by passing in something else (polymorphism). Just a few ideas :-)
 
@ircmaxell Is it worth to copy the whole string in <= 5.6?
 
Thanks @Jimbo ! I will read more about this!
Thanks @Patrick!
 
5:04 PM
@Miguel_Velazkez give me minute, I'll try and rewrite a little to demonstrate Jimbos points
 
@bwoebi can you see a better way without duplicating everything?
 
@ircmaxell nothing easy. First make it work… one can optimize later. hmmm.
 
Macros.....macros everywhere.
 
user895378
@bwoebi TBH I wouldn't worry about it until much further down the road. If people want to maximize performance they should be capable of upgrading. I get that PHP7 isn't actually a thing yet, and perhaps @ircmaxell wants to drive adoption now instead of waiting for a far-off release ... but still.
 
5:09 PM
@rdlowrey also… until recki will be stable software php 7 release will be near… I assume.
 
user895378
My personal strategy is ... optimize for new versions, achieve compatibility for everything else.
 
Would it be reasonable to unify all uses of the scalar "type" names to constants? Such that we'd have TYPE_STRING, TYPE_INT, TYPE_FLOAT, etc., which can then be passed-to/returned-from functions like settype and gettype respectively?
 
sure, why not
 
@ircmaxell I mean, in core.
 
I know
 
5:13 PM
@Miguel_Velazkez paste.jesse-obrien.ca/F6V I stopped midway through, but I hope you get the idea
No guarantee that the code works as I just scribbled that down quickly :)
 
Thanks
 
Rather... expanding -- I had this thought for character encodings before; ENCODING_UTF8, ENCODING_ISO8859, etc., which should then be used in all occurrences. Optimally, expanding this requirement to extensions.
Similarly for types, though, among other potential candidates.
 
@Miguel_Velazkez oh I forgot, in Foo you would also require a validator in the constructor and then use the methods where you need them. Every class just does one thing
 
@Patrick I get how to use the OOP code/syntax works but not yet how to design something efficiently. So Thanks a lot! Do you recomend a book or something about oop design?
 
We're 21 ★ away from 10,000 on Github! Tight race between us and @reactjs for being the first Facebook project. https://github.com/facebook/hhvm
 
user895378
5:16 PM
Yeah ... saw that.
 
user895378
People love them some bandwagon. PHP people more than most.
 
20
actually 14, 20 was just for dramatic effect
 
stackoverflow.com/a/16356866/2834339 make this a bookmark and then slowly work your way through all the material listed there. Will probably take a while but it's worth it :)
 
@AndreaFaulds Something for the safe casts RFC may be to explicitly state where to_* is different than the equivalent filter_var.
 
thanks a lot @Patrick! Will do!
 
5:19 PM
@rdlowrey i can haz laravel pls?
oh wait i meant $new_hip_framework
srry sir pls halp me
 
@rdlowrey I think the ruby community is the same they just don't have that many wagons
doesn't??? wtf was I thinking
 
*don't was correct
 
@tomwilde I know
 
don'snt
 
:P
Staph making phun of mi
 
5:27 PM
so I'm waiting for the hhvm to reach 9999 stars to unstar and ruin their moment.
 
:P
Do it!
 
> error: unknown type name 'uint32_t'
wait, what?
 
@tomwilde I, am literally doing the same.
 
8 left to go..
 
@ircmaxell are you compiling for 5.4 or 5.5?
 
5:30 PM
5.5
 
yep… Had that issue too… everything was fine on 5.6 and then blew up on 5.5…
 
#include <stdint.h>
 
5:42 PM
weird, phpunit isn't giving me a backtrace for an error I'm getting
 
When phpunit don't work it's time to bring out the big guns fc06.deviantart.net/fs50/f/2009/305/9/0/…
And by big guns I mean var_dump of course
 
@Sherif oh I thought you were talking of phpdbg :-P
 
Nah, var_dump is what serious programmers use.
var_dump(new Exception('ohnoes'));
I once sent a junior dev a ticket with "Why does this work in CLI interactive mode var_dump(throw new Exception('ohnoes')); ... please investigate a fix!"
Poor kid actually spent the whole day looking for a fix.
 
oh, you mean the common idiom of

    try {
        throw new \RuntimeException('blurp');
    } catch(Exception $ex) {
        var_dump($ex);
    }
 
@tomwilde ctrl+k
 
5:50 PM
@PeeHaa lel not working
 
chat MD #fail :P
 
\o/
 
so, what else can I say about the hashkey thing (renamed to toKey) ?
 
@JoeWatkins Honestly, I think keys should be allowed to be compound. foreach can already support it.
Removing the cast in foreach would be better, in my opinion, than offering another magic method for the object.
Forget the fact that arrays restrict it inherently for now and just let people have compound keys in foreach.
Then if I want to implement an iterator that returns non-scalar keys I can :)
 
5:55 PM
I'm not sure that's a limitation of foreach
that's a limitation of the hashtable structure isn't it ?
I thought about how you might use a zval for a key, but the only ways I can think of doing that are quite horrible ... and incomplete ...
 
@JoeWatkins But seriously, I cannot remember to ever have seen any need for __hashKey…
 
@DanLugg it's time
 
@JoeWatkins Pre 5.5 foreach threw warnings 3v4l.org/0tfSW
 
I'm not talking about necessarily changing the capabilities of ht to support non-scalar keys though. I'm just talking about when you want to implement your own iterator.
Like a map of maps.
 
6:05 PM
@JoeWatkins well, that makes more sense. That's an internal function you can overload...
 
well since there is no super object in php, we can't provide default ... that has to be down to ext/user land ...
nor can we have quite the same contract, but it's definitely a thing, and the reasons it's useful for java, in those situations it is useful, stand for us too ...
@bwoebi can you think of a way to have zval keys ?
I hear ya @Sherif but everything is easier if we start with a table that can have non-scalar keys ...
 
@JoeWatkins we have no super object, but we have a handler which invokes __toString. Or outputs a catchable fatal. At that level we can do things…
@JoeWatkins when you tell me what hash value you want to have for the zval…
 
@LeviMorrison Good idea.
 
@JoeWatkins well. You could add them, but how would you uniquely access the value with that key?
 
I dunno I get stuck thinking about it ...
I dunno
 
6:12 PM
There's the issue ;-)
 
@JoeWatkins That's not what I'm saying :)
Never mind
 
Benchmarks using time()?
Really?
He couldn't afford microtime(true)?
 
not sure what that's about really ... he does mention "useless" ...
 
I don't think the bench mark of splat itself is necessarily a useless metric. I just think his bench mark is useless in that it could be off by an order of magnitude.
 
6:21 PM
OK, making an executive decision on safe casts.
It'll piss a few people off, but... it should throw an exception.
 
You're an executive now?
 
it might cause it to fail ...
 
Not really. But I am the RFC Author, I do what I want! <table_flip.shift_jis>
 
Hey guys :)
 
@JoeWatkins Eh, it could still go to vote I guess. But I'd make this the preferred option.
 
6:23 PM
3 way votes are difficult to get a majority from ... we have time, do two votes I would ...
 
NULL vs Exception?
 
@AndreaFaulds Did you consider the suggestion of throwing an exception unless a default value is specified?
 
@NikiC I'm considering it... but it seems kinda weird
What would the default value of the default be?
Given it can't be NULL or FALSE
Do engine magic to have no default value?
 
@AndreaFaulds huh what?
if the default value isn't given, you get an exception
 
Right, but what's that parameter's default value? Nothing?
 
6:24 PM
so you can easily support all three behaviors (and more)
 
@AndreaFaulds nothing.
 
@AndreaFaulds internal functions don't concern themselves with things like default values
 
Yeah, I know...
Hmm. This works, I guess. Though if (to_int($foo, FALSE) === FALSE) feels so icky
It seems like an abuse of the default... though in that case you could just do a try/catch
But then... why do that at all? Why have a default?
If passed garbage, assume a default doesn't sound good to me
 
@AndreaFaulds $this->addPendingOperation($rfc->get("Safe casts without null by default")->vote("REJECTION!")); … That's maybe too harsh, but I strongly feel exceptions are the wrong thing for an external-input validation function. Maybe, the default value… I'll think about it.
 
That's almost as bad, if not as bad as, an explicit cast
@bwoebi to_int($foo)->assert() (exception) if (to_int($foo)->success) to_int($foo)->getOrAssert()
idk :/
 
6:29 PM
@AndreaFaulds Why not? If it's up to the caller to pass default value if there is a sensible default. For some things the exception catching is just going to set a default there instead. e.g. when someone requests 'page=fish' where page is meant to be a int, then you're going to catch the parse failure and set a default value of 0.
 
The problem is partly trying to satisfy two different use cases
@Danack True.
Also, it'd be nice if I didn't need two defaults...
 
@AndreaFaulds Correct. Also, as I said on the ml, it's easy for an user to write a wrapper which throws an exception.
 
Presumably the default should only be of the same type as the to_xxx method e.g. int for int, string for string...
 
to_int($_GET['foo'] ?? NULL, NULL) (ew)
@bwoebi I'd rather it throw an exception by default... can always write a wrapper for that.
 
@AndreaFaulds inefficient.
 
6:31 PM
So's your suggestion.
 
no?
 
Andrea, throwing and catching exceptions has a LOT more overhead than checking for null.
Not just resource overhead, but it simply takes more code too.
 
Hmm.
Does it at an internal level? Isn't it just a jump?
 
No
 
It also plays silly buggers with the parameters in the stack trace....the exception keeps reference of them.
 
6:34 PM
@AndreaFaulds creating exception object, cleaning up, backing up eventual parent exception, storing current state (for trace) etc.
 
Throwing an exception means a) creating an exception (alloc init object) b) collecting a stack trace (alloc a bunch of arrays) c) performing stack-unwinding.
 
Exceptions are only cheap if they aren't used ;)
 
to_int_assert, to_int ?
 
eek
 
6:36 PM
to_int, try_int?
 
I cannot tell you from the names which one probably would throw the exception… no.
(I'd guess try_int… trying => exception… to_int => the other case?)
 
Wrong! :p
 
You shouldn't need two function names....imho it's okay to have one function and have the behaviour change if the user passed a default or not. But I still agree with levi that just having the function do "does this value represent an int" and then let the exception or other behaviour be done in userland.
 
^ this
 
my only problem with the default thing is that if (to_int($foo, NULL) === NULL) would bother me
 
6:39 PM
to_int($foo) - throws exception if not parsed.
to_int($foo, 4) - returns 4 if not parsed.
 
And how do I check - without exception - if the initial cast was successful?
 
I missed the second argument discussion; what does it mean?
 
1 min ago, by Danack
to_int($foo) - throws exception if not parsed.
to_int($foo, 4) - returns 4 if not parsed.
 
@bwoebi You can't .....as I said I prefer not having the choice of what happens if something is not parseable.
 
@Danack jup. Just return null, that's best…… ;-)
 
6:42 PM
@LeviMorrison The conversation isn't that long - but basically it's throwing and catching exceptions are overkill if a sensible default value exists.
 
graph theory is hard
 
@ircmaxell Only hard graph theory is hard.
^^
 
try_to_int($input, &$output) : bool;

to_int($input) : int;

if (try_to_int($input, $int)) {
    // $int is the parsed integer
} else {
    // $int == null
}

$int = to_int($input); // $int is the parsed integer
                       // throws InvalidArgumentException on fail
                       // or FormatException or whatever
 
ehhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
*shrug* that's how I've mostly always handled the parse_something/try_parse_something
 
6:46 PM
@DanLugg * runs far, far away *
 
@bwoebi Good, and stay there ;-)
 
looks like something from .Net
 
@DanLugg no, just running away from your code, not from the chat/discussion :-P
 
Honestly though, what is inherently wrong with my suggestion? Is it the reference hate?
Because I think this (and other "parsing" operations) are great candidates of it's use.
 
> Is it the reference hate?

Pretty much.
 
6:49 PM
@DanLugg Personally, I'd like it better as to_int(&$var) returning bool, but ... yeah, reference hate. :)
 
I, too, hate references.
 
References are a perfectly valid and usable feature. I don't understand why everyone hates on them like nazi brussel sprouts.
 
I don't, but everybody else does, so ...
 
3 hours ago, by salathe
@DanLugg I can hear the "so, just go and use C#..." voices already :P
 
@DanLugg Well, I had done a lot of porting from the PHP 5.6 codebase to phpng in phpdbg recently. The HashTable access previously was if (zend_hash_find(ht, str, str_len, &ptr) == SUCCESS) … now it's just if ((ptr = zend_str_hash_find_ptr(ht, str, str_len))) … much more readable somehow. And feels much better to write that code :-)
 
6:50 PM
They can be abused, and can introduce code complexity, but that can be nearly argued about anything that we're not holding people hands through.
@bwoebi And here's the core issue: I completely disagree.
 
@DanLugg tell me something not so obvious next time ;-D
 
if ((ptr_wrap = zend_str_hash_find_ptr(ht, str, str_len))->result == SUCCESS) {
    // use ptr_wrap->ptr ...
}
 
stop bloating this concise API :-(
 
No!
 
/me is overusing smilies again ...
 
6:55 PM
Honestly, the ref arg version was more readable IMO, so this discussion will just spiral.
@Narf Issue with that is you lose the original value.
 
@DanLugg No it wasn't. The example just doesn't make you see how terrible it was to use.
 
well... then I'll not argue further if I can't win this ;-)
 
yay, figured out the graphs. I think
 
@DanLugg They complicate both user-land code and definitely complicate internals.
 
@NikiC well, the most terrible part was the (void **) cast, but that's another story…
 
6:56 PM
@bwoebi not just the void cast, but that nobody knew how many levels of indirections you need to call that function
 
@DanLugg Not necessarily, especially since there's validation prior to the cast ... you just don't assign the result if it doesn't pass validation.
 
always felt like it needed a zval ******* or something like that ^^
 
@NikiC Do you have an example of where it was ridiculous?
 
I don't mind references in C++; in fact they are the preferred way to pass around arguments unless you need pointers.
But in PHP? They suck.
I hate them.
 
I have a variable in which i am fetching content from DB. Content includes twig as well. Now i want to print that content inside twig, is it possible to get twig inside twig, if not how would it work?\
 
6:58 PM
@DanLugg well, the one time you needed a *, other times a **, str_len once included the NULL-byte, once it didn't…
 
@DanLugg What you actually pass to zend_hash_find is a zval ***, while you usually need a zval *. Makes for some really ugly code ;)
 
@bwoebi I have it working
 

« first day (1467 days earlier)      last day (3474 days later) »