« first day (1885 days earlier)      last day (3062 days later) » 

9:04 PM
I'm a bit confused. The layers you are referring to here, are they steps of handling a request, such as bootstrapping, controlling and sending response, or rather different concerns of handling a request, such as model, dbaccess, authentification, without a regard to the order in which they happen?
 
In object-oriented design, a layer is a group of classes that have the same set of link-time module dependencies to other modules. In other words, a layer is a group of reusable components that are reusable in similar circumstances. In programming languages, the layer distinction is often expressed as "import" dependencies between software modules. Layers are often arranged in a tree-form hierarchy, with dependency relationships as links between the layers. Dependency relationships between layers are often either inheritance, composition or aggregation relationships, but other kinds of dependencies...
In computing, an abstraction layer or abstraction level is a way of hiding the implementation details of a particular set of functionality, allowing the separation of concerns to facilitate interoperability and platform independence. Software models that use layers of abstraction include the OSI 7-layer model for computer network protocols, the OpenGL graphics drawing library, and the byte stream input/output (I/O) model originated by Unix and adopted by MS-DOS, Linux, and most other modern operating systems. In the Unix operating system, most types of input and output operations are considered...
 
@FélixGagnon-Grenier I'm not sure how familiar you are with programming in general, but I think there are a few obvious "layers" in a typical web response.
 
@FélixGagnon-Grenier You normally put into a layer that is on the same or equal level of processing. It's one way to create separation of concerns. If you inject the same DIC into every layer, the each layer also needs to be concerned of accessing the DIC and certain other layers from it. The DIC has become an interface and intermediate to exchange messages with all other parts of the application. Boundaries are broken.
 
It's hopefully obvious that generating HTML is different from querying data from a database or doing a web service call.
Taking this a bit further you can hopefully understand that the objects and functions used to interact with these things are separate and independent from the others.
Any code that generates HTML and also has a dependency on a database handle should be inherently suspicious.
Depending on your task there are probably some other layers that make sense too. The more complex the task the more layers you can theoretically form.
It is my experience that programmers making websites tend to overcomplicate their code (and layers).
This could just be experience bias though.
Anyway, each "layer" typically has a few functions and objects/methods for interacting with it from other layers.
 
I'd coin it this way: It's easy to overcomplicated things as a programmer, and harder to write less code that does what you actually need.
For layers it's one concept to say that one layer only interacts with the layer above and the layer below.
 
9:17 PM
@hakre The difficulty is usually identifying the layers :D
I would expect that an object that gets injected with a large number of dependencies is blurring the lines.
 
yeah. so, if I understand some things correctly, html generation would interact with a model layer ( I think) which would have services accessing the dbaccess layer
 
@LeviMorrison Yes, as so often ^^. I don't know if it's a helpful tip, but I normally "put" the "same kind of processing" into the same layer. If the type of processing is different (e.g. on a more granular leve) it belongs into a different module (and layer).
 
Eh, I think the "model" terminology is bad simply because it's been butchered by so many people.
But I don't think the html generation layer should invoke any calls into other layers.
Rather other things invoke calls into it.
"Here is this data; render it please"
 
yeah. I think the formulation was off, but that's more the way I see/use it
 
It depends on the kind of job you'd like to get done. For templates and PHP, Decorators with __toString() implemenation and a simple echo work wonders in simple templates.
 
9:23 PM
...or an explicit render() function rather than abusing a string representation.
 
function render() {ob_start(); echo $this; return ob_get_clean();}
 
that leaks ob levels when exceptions occur....and is still an abuse of the presence of toString.
 
I have to actually ask, did you mean function render() {return $this->__toString();}or function render() {echo $this->__toString();}?
 
I think hakre understands it is abuse :D
 
it's abuse, sometimes even for a good cause. If you'd like to stream out large data, you need to use the stdOut stream.
If you create an interface that allows a decorators used around template variables to do the one or other under the hood can be helpful. Especially as you only do that in the template layer.
can, but must not. last time I had to do that decision I decided to not decide it and it went well for that. but it depends on the job and how much flexibility you need for what.
 
9:31 PM
No....the issue is that toString is meant to be used to return a string representation of the object. Using it to render HTML mean that you are using it as a transformation function....and while that is a hack that is useful, it sucks when you have more than one possible way of transforming an object to HTML.
 
I didn't say it was for rendering HTML. Imagine you've got a variable that contains a date. Now you pass that date into a template as a variable and echo it out there. Now you need to translate the date into a different language as the response is in it. You don't need to change the template.
 
MailGun API??? :o
 
And using __toString helps make that process be clearer how?
 
ad on stackoverflow
 
@Danack It's an interface with echo. The said string representation of an object whereas object is a template variable for example.
<b>Date:</b> <?php echo $date; ?> (just simplified).
Can't say if it's all clearer, but in case you need to switch to render() or a different name later, it's not much of a problem normally.
gn8
 
9:47 PM
I have three images wrapped in anchor tags. When one of them is clicked I want it to redirect to a new page and query the database for more information on the image that was clicked. How do I do this?
 
that moment when your CPU has been grinding on a problem for literally hours, and you realize you forgot a 0...
 
@ircmaxell That moment when your CPU has been grinding on a problem for literally hours, and then you get a segfault in the result printing code
 
@MarkusHallcyon put some information in the link that the image is wrapped by: <a href='/foo?link=image1&whatever=bar'><img src='/image1'/></a>
 
okay
and how do I "check" for that when the page redirects?
 
@NikiC use the dump file? (this is btw. why you always should generate a core dump…)
 
9:54 PM
@LeviMorrison why did you choose an AVL tree over an RB tree in Ardent?
 
@Danack hey thanks for the help, how would I check for that when the page redirects?
 
@MarkusHallcyon the query parameters get put into the ($_GET)[php.net/manual/en/reserved.variables.get.php] global variable, or if you're using a framework they are likely to be available through a request object.
 
@Danack other way around ([]())
 
too late......
 
@Danack so does this look right: html: "href='/foo.php?link=image1" php: "if($_GET["link"] === "image1") {};"
 
10:01 PM
@NikiC ah :-)
 
@rtheunissen Easier to implement.
But honestly if someone wrote a red black tree I would definitely take it seriously.
 
@MarkusHallcyon yes, though you probably want an isset($_GET["link"]) or array_key_exists("link", $_GET) before the 'if' statement, to check that there is anything there to even compare.
 
@Danack okay ill do that, thanks!
 
I've written AVL trees several times because of university projects or the language I was using was missing any sort of balancing tree.
So while "easier to implement" may be subjective, it is definitely true for me :D
 
@LeviMorrison Cool thanks :)
 
10:04 PM
@LeviMorrison time to update? :) github.com/morrisonlevi/Ardent#php-54
 
I did experiment with a Trie and it was slower.
I expect that is because it rewrites the structure more often and the writes are much slower than the reads or something.
@FlorianMargaine Probably, but until I touch the code I won't adjust the version.
:/ I am still bummed we can't implement empty() on a container (not a member of the container).
Or did we fix this recently?
Ah, no, that was stuff with offsetExists() and stuff and interaction with empty().
 
YES absolutely, I've mentioned this several times. Seems like it should behave like count(), and should expose an internal handler as well.
 
It's basically a false or null right now, I think?
 
I suspect some people will want empty() without being tied to count(), though. For example if you do not know the full size of the container.
 
10:16 PM
For sure, but be used in a similar context.
count(container) === 0 --> empty(container)
 
Hmm. The ArrayObject class is hooking in there somehow.
LOL actually it probably isn't.
empty($anyObject) is true, I think.
Yep.
 
@LeviMorrison 3v4l.org/31mju no?
 
Bugs sometimes have the weirdest origins …
 
@LeviMorrison I think always false?
 
@rtheunissen nah, try an object implementing Countable … Mh, I think I've missed the dpoint
 
10:33 PM
@bwoebi 3v4l.org/T9QNd ?
 
yep
 
All false?
Oh I see your edit now.
I was excited for a second :p
 
Oh oops, I just flipped it when I wrote it here.
I was doing !empty().
Some background on why I think having a hook for empty() is important: gist.github.com/morrisonlevi/7d716f67789d42115eb8.
/cc @bwoebi @rtheunissen @Andrea @NikiC @rdlowrey @salathe @ircmaxell @Danack @DanLugg
Think we should RFC it for PHP 7.1?
 
not sure... Would you have __empty()? or PECL only?
 
hmm
isn't empty fundamentally a misnomer anyway?
it may be named that, but that's not what it does
it's inverse falsey isset
consider that Spl just uses isEmpty()
 
10:41 PM
Sure, but arrays and strings ("Containers", if you will) act differently when they have no content.
 
@Andrea it is…
 
It makes sense that objects that are Containers could hook in the same.
 
okay, get @ircmaxell to revive __toInt, __toBool and __toFloat :D
 
@ircmaxell I was thinking an interface like count and Countable.
(though not sure what to name it)
 
@LeviMorrison yes, but only because they are falsey
 
10:43 PM
@Andrea It makes writing objects that mimic them impossible.
 
adding a hook for this means that empty() now has more complicated behaviour
 
@Andrea Better there than in user-land, in my opinion.
 
@LeviMorrison the one internal object that does mimic them is hated for it
(DOMNode IIRC)
 
What if empty is considered equivalent to count == 0 for a Countable implementation?
 
@rtheunissen That would work for many cases but there are cases where an object can know if it is empty but not how many elements there will be.
 
10:45 PM
anyway, if you're affecting empty() you want to affect all falsiness tests
so __toBool is the way to go
 
@Andrea no. no. no.
 
@bwoebi that is my opinion as well
 
@LeviMorrison Emptyable
I don't know... Part of me likes it, part of me doesn;t
 
That sounds more like the act of emptying something.
Anyway, I like count() hooking with Countable.
 
Magicable
 
10:46 PM
I like foreach hooking with Traversable.
 
I feel like a behavioural change is all that required - no new interface or magic.
 
It seems like we should have a hook for empty() as well.
It's like the only missing piece for "Containers".
 
Countable is inherently linked to something that is "emptyable".
 
user895378
golang's implicit interfaces are thebomb.com
 
yup
 
10:48 PM
again, empty() isn't special, it is literally isset($a) && $a != false
 
Unless there's a case where something with count > 0 is considered empty, or vice versa.
 
there's no empty hook for arrays and strings
[] and "" are falsey and thus empty
changing the behaviour of empty() to not align with falsiness would be bizarre
 
empty([]) and empty([1]) makes it seem like there is though, because it operates as its own value type. There is no hook but it behaves as if there is.
 
@rtheunissen Yes, but not everything can know ahead of time its full count.
 
user5029208
are there any free inventory management apps/software/freeware/etc out that ANYONE can recommend. Not free trial, FREE FREE
 
10:49 PM
@rtheunissen it doesn't behave as if there is
 
And often we only care if there is a single value.
 
it acts the same as @!
 
[] and "" are logically just engine hooks that aren't exposed.
 
@LeviMorrison Good point.
 
@LeviMorrison they are not engine hooks in empty()
they are special cases of falsiness
I can do if ([]) { too
 
10:51 PM
They're own special cases of falsiness is what other container types don't have access to.
 
So write a hook that does truthiness for an object instead of just empty().
 
You can consider that as a hook.
 
@LeviMorrison we have that internally
and Anthony proposed that for userland
 
How does it work internally?
 
When? Seems I've forgotten that.
 
10:52 PM
@rtheunissen handler for conversions
 
Oh, you mean general conversions.
 
cast_object with an IS_BOOL type maybe?
 
Well I like that empty() is explicit.
 
there were at least two RFCs, I dunno if either went to internals
 
if ($object) is an implicit one.
 
10:53 PM
@LeviMorrison same here.
 
Is it meant to be possible to define VIRTUAL_DIR without defining ZTS ?
 
I don't like making things that were consistent inconsistent, it makes things break in subtle ways
empty() is broken, sure, but that doesn't mean you should "fix" it
 
Hey there, anyone knows if there's a way to change the app structure(or folder structure) of a Laralvel project?
 
It's probably all hardcoded in static methods
sorry facades
 
@Andrea Sounds like a great candidate for PHP 8, imo.
It would be great for this code to be fully polymorphic with expected behavior:
if (!empty($list)) {
    //...
    foreach ($list as $value) {
        //...
    }
} else {
    //...
}
 
11:01 PM
@LeviMorrison that is the most beautiful thing I've ever seen.
All day.
 
I'd love to see a foreach / else

foreach ($list as $value){

} else {

}
 
@LeviMorrison no
 
^ That is one thing that I will never get behind.
 
empty() is a weird language construct and doesn't mean what it says
make arrays have ->isEmpty() instead
 
@jbrahy It doesn't allow for things to happen before and after the loop but only if there are values to loop over.
 
11:03 PM
@LeviMorrison I think if we add something like this, we should rather allow overloading the bool cast rather than empty() directly. if ($array) {} is a perfectly legit and commonly used way to check the emptiness of an array and it should apply to other structures as well (if we also want it in empty, that is)
 
@NikiC I'm beginning to think the same.
 
a reminder that lolphp loves how SimpleXML is the sole exception to the all-objects-are-truthy rule
 
What about GMP objects?
Are they always truthy?
 
that's a good question
 
Most people who use empty() seem to use it for containers.
Not general boolean falsey stuff.
 
11:06 PM
@LeviMorrison indeed
$ php -r '$x = gmp_init(0); var_dump(!!$x);'
PHP Catchable fatal error:  Object of class GMP could not be converted to boolean in Command line code on line 1
gotta love PHP
 
I don't have any build of PHP with GMP.
 
ooh wait that's a catchable, let's override it
 
if (gmp_init(0)) should be consistent with that, yeah?
 
$ php -r 'set_error_handler(function () { return true; }); $x = gmp_init(0); var_dump(!!$x);'
bool(true)
@LeviMorrison yes
 
Andrea, I like your tag line.
 
11:09 PM
@Porlune "$appreciative_remark"
 
I want to take it and add "$stolen_witty_comment";
Okay, so I'm weighing the pros and cons of rewriting most of my backend in nodejs, which do you think is more scalable? php or node js?
 
@Porlune depends what you're doing
 
a social networking site
 
@NikiC If we add the hook such that it uses an interface it wouldn't break any existing code to add it, correct?
 
@Porlune node would be ideal for a chat server or API, PHP for the main site
 
11:12 PM
okay, so a blend of the two then it is. That's very similar advice I've gotten recently too.
thank you
 
Even if a method of the same name exists it wouldn't implement the interface currently.
 
Yes
It could only break expectations
 
Though "This expression always returns true" is not exactly a useful expectation, so I wouldn't worry
 
Unfortunately we use a magic method for string conversions.
 
11:13 PM
@NikiC that's the kind of expectation that subtly breaks lots of things if you change it
 
@bwoebi You've fixed one typo and left the other one ...
 
And I fear if I propose a general boolean conversion and not other conversions people will complain it is incomplete.
 
the kind a static analyser won't pick up
@LeviMorrison boolean conversions are the one I dislike the most
 
@NikiC Eh, people do it for objects that are not null, so theoretically it could break.
 
precisely because people can currently assume objects are truthy, unless they're SimpleXML (BECAUSE PHP!)
 
11:14 PM
Since you could now have a falsey object that isn't null, but that's not exactly what they were testing.
It's what they wanted but not what they wrote.
 
@NikiC I saw that … after the push ^^
 
@LeviMorrison this is the problem of falsiness
if I were to write a new language, I wouldn't have it
alas, PHP is not a new language
I'd argue falsiness works in C and that's just about the only place it does
because in C everything is a number
 
@Andrea Eh, I'd say it works in C++ but only because you can overload it.
Basically I'd like a built-in function/construct that works with any type that can identify firstly if it can be iterable, and if it is if doing rewind(); valid() will be true without having to do that.
 
11:37 PM
@NikiC So I found out where the brk() system call is being made, and they're not totally unsensible. I guess the cost of the system call might be less on other systems, but it still seems annoying to have to call it 3 times for every request github.com/Danack/TodoList/issues/1#issuecomment-164591310 /cc @FlorianMargaine
 
@Danack hey when the page redirects to "page.php?link=4" and I do: "if (isset($_GET["link"]) && $_GET["link"] === 4) { echo "worked"; };" it doesn't echo anything, am i doing anything noticeably wrong here?
 
@Danack what's that? microoptimizing on the wrong end?
 
@bwoebi It's 10% of my request time....
 
whut…
 
For non-logged in requests, that process no data of course ;-)
 
11:42 PM
or is OS just scheduling some other processes in between the syscalls?
 
my suspicion is that the VM is just being really really shitty.
But my local VM behaviour is very similar to the AWS environment.
 
The VM…? Don't VMs usually allocate a fixed segment of memory at startup time?
 
Yeah......so it would have to be doing something insane like checking the memory it still there and usable. It's just a guess.
 
I can't believe that is the VMs fault
but feel free to test it on another host…
 
@bwoebi depends on the model, often no
 
11:54 PM
hmm
 

« first day (1885 days earlier)      last day (3062 days later) »