« first day (3684 days earlier)      last day (1250 days later) » 

1:28 AM
Memory leak in big array of strings ・ Arrays related ・ #80373
 
 
2 hours later…
3:02 AM
@Jeeves doesn't seem like a bug
 
3:48 AM
@Tiffany I'm actually surprised the second script is only double.
 
3:59 AM
Some internal efficiency?
 
4:19 AM
The first script should be creating an array all referencing the same zval. I see the second he says more than 128 MB, which makes sense.
Each array element then likely allocates a new zval to hold the modified string.
You were right, it's not a bug.
 
5:00 AM
@Trowski I read this wrong, thought you had said the second example used less memory for some reason
There was a similar bug report a couple or so weeks ago that was closed as not a bug. Basically people using inefficient code trying to find reasons that something is "broke" when it isn't... it's unrealistic
What did the bug reporter expect, honestly? -_-
@Trowski not less memory than the first example, but less than double
 
@Tiffany I misread it the first time, the bug report says "more than 128 MB", not exactly 128 MB.
 
 
2 hours later…
7:20 AM
add "asian water monitor" (Varanus salvator) to the list of unwanted creatures that have been dispatched via snake catching "tongs"
 
morns
 
7:39 AM
<?php
require_once 'Requests/library/Requests.php';

Requests::register_autoloader();

$url = "https://jsonplaceholder.typicode.com/todos/1";

$request = Requests::get($url, array('Accept' => 'application/json'));

print_r($request->body);

echo $request->body->title;

?>

I am trying to get title from json, but not working
 
7:50 AM
Well without knowing what library you use to get requests, accepting application/json doesn't mean when it's returned PHP will return it as a JSOn parsed structure. you likely have to do that yourself
 
what is the "Requests" library you referenced there
 
 
1 hour later…
Wes
9:01 AM
les morningables
$depth in json_decode should be nullable
or this. been wanting this for a while. much better than named parameters imo.

json_decode("{}", TRUE, default, JSON_THROW_ON_ERROR);
 
9:18 AM
@Trowski Anything to watch out for when benchmarking amphp http-client?
 
9:58 AM
@NikiC Depends on what you're trying to benchmark.
 
Wes
10:09 AM
i am feeling brave enough to be working on a amphp based package
 
@Wes o/
 
Wes
have no clue whether i will succeed. lots of things to learn
 
nothing much. just about event loops, threads, async IO, etc. usual run-of-the-mill stuff.
 
Amp v3 will be so nice, you'll have to know almost nothing about all that. :-)
 
wishful thinking
 
Wes
11:04 AM
$timeoutMS $timeoutMs $msTimeout $MSTimeout
gotta love this code where exceptions are thrown by an helper function that has no call stack
or rather, no call stack that is useful to understand what's going on.....
i don't even know how's that possible
 
11:25 AM
bah
 
Mysqli warning Packets out of order. Expected 1 received 0 ・ MySQLi related ・ #80374
 
@MarkR I used this one : requests.ryanmccue.info
 
11:49 AM
@Srinivas08 I don't see anything about it decoding JSON for you automatically.
 
12:25 PM
I used
$response = json_decode($request->body);
it fixed my problem, earlier I trying with
$response = json_decode($request->body, true);
 
You should always pass true IMO
 
If i am passing true, i am getting errors :Notice: Trying to get property 'title' of non-object in
to access
$title = $response->title;
 
@Srinivas08 if you pass true, it'll return associative arrays rather than stdClass objects
 
yes
 
so you'd need to do $response['title']
 
12:32 PM
@Stephen worked, i generally ave a habit of passing true...
 
I used to do everything as assoc... learnt that the hard way not to do it anymore =\
 
@MarkR wut?
 
@MarkR you mean because you define classes with the properties you expect, or you're just free-ballin' it with \stdClass?
 
Casting the whole thing to a nested assoc array caused me no end of grief when I needed to work with things as object, especially deeply nested things.
 
Can I ask why?
 
12:45 PM
So now I prefer to decode without assoc and cast to array as necessary
 
@PeeHaa Several things upstream when manipulating structures, mainly to do with empty arrays for maps, sometimes different at different parts of the same structure
There may be an easy way around it im not aware of, but for me I came to the conclusion it was better to not throw away any information and maintain the object style
 
1:02 PM
Defined objects FTW.
 
Hello all, how can I submit a form depending on the data sent by another form?
I have this code but when i hit the 'test1' button there's no 'true' echoed(noting that this code is just to communicate my idea). Any suggestions?
echo "<form action='' method='post'>
<input class='btn btn-primary' type='submit' value='test' name='test'>
</form>";
if(isset($_POST["test"]))
{
echo "<form action='' method='post'>
<input class='btn btn-primary' type='submit' value='test1' name='test1'>
</form>";
if(isset($_POST["test1"]))
 
mornin
 
1:33 PM
@LalouiAbdelkrim when the second forms submit is pressed test1 is set, but not test, so echo "true" will not be executed
 
Morning, All!
 
Ohai Statik
 
@DaveRandom Guess what?!? IT'S MONDAY! \o/
@PeeHaa o/
waits for @DaveRandom to jab in eye
@PeeHaa So what have you been working on so diligently?
 
Work work
 
@makadev oh I see the second if must be outside the first if, thanks!
 
1:39 PM
We do e-commerce order things so this is a crazy busy time for us
 
gotcha
 
2:06 PM
Hi.
 
Wes
reading some obscure Google Chrome api, it's like 30 pages on one topic, but then it says no this is deprecated, use this instead
and there are no examples at all of that
 
If I write a test case trying to break PHP 8, but it still passes does it make sense to add a PR to PHP or is this just going to be noise? e.g. 3v4l.org/Krcvk
 
2:25 PM
@Wes It has the deprecation notice at the end of the document?
 
Wes
no, it's deprecated in the reference, but the guide doesn't match the deprecation yet
 
2:40 PM
I just saw a thing saying that the Perseverance rover will carry microphones to mars.
what happens if they hear this: youtube.com/watch?v=FInmC8ILpH8
 
2:54 PM
parameter skipping got as far as an RFC vote in 2015: https://wiki.php.net/rfc/skipparams
It was declined largely because people preferred to solve the problem with named parameters
I'd personally be happy with either or both, but now that we (finally!) have named params, skipping is probably even less likely to pass a re-vote
 
Wes
i remember that. named parameters in js for me are like, oh this is cool, but then i go like, shit i really hate writing the names again, so i use undefined instead
 
hello
+"Lines": {#683
+"0": {#676
+"Create_Line": {#679
+"ItemIdentifier": {#678
+"Reference": "4230000699300"
}
+"Label": "PULL EN MAILLE AJUSTE ."
+"NetUnitPrice": 29.9
+"Origin": "ECommerce"
+"Quantity": 1
+"UnitPrice": 29.9
}
}
+"1": {#687
+"Create_Line": {#688
+"ItemIdentifier": {#691
+"Reference": "4230000701508"
}
+"Label": "Robe courte imprimé animal ."
+"NetUnitPrice": 69.9
+"Origin": "ECommerce"
+"Quantity": 1
+"UnitPrice": 69.9
}
}
}
any idea to remove the keys of this object?
the 0 and 1
the structure should be like this
Lines->Create_Line directly without key
 
Turn it into an array.
 
Wes
i am not quite sure the purpose of named parameters is. too many parameters, hard to understand what they are for without reading their names? if that's the case, i use a "struct" object

or is it for skipping parameters? the solution is extra verbose
 
@Wes Because Python has them.
 
Wes
3:05 PM
makes sense :P
 
I'm using Laravel
@Sara I cant, i should use objects
 
Why?
 
@Wes I don't think using a struct object is really the way to go, except if you want to pass that around
 
@Wes this is a simple structure
+"Lines": {#683
+"0": {#676
+"Create_Line": {
//SOME STAFF
}
}
+"1": {#676
+"Create_Line": {
//SOME STAFF
}
}
I need to be like this
+"Lines": {#683
+"Create_Line": {
//SOME STAFF
}
+"Create_Line": {
//SOME STAFF
}
}
 
Wes
of course js people like to do stuff inline and cram everything in their signatures, because heaven forbid one should create simple structs/dtos. too hard to create a new file
 
3:12 PM
@Boytun Then how do you propose to access those properties if they don't have names?
 
I'm trying to understand how named arguments work with unpacked arguments. I think this should work? https://3v4l.org/Nf1qs

The RFC only talks about this case being invalid `array_fill(start_index: 0, ...[100, 50]);` which is understandable, but in my case I think it should work?
 
@Boytun i) Please use something like gist.github.com to avoid posting walls of text ii) It looks like you should foreach over the code, and create a new array/structure with the data how you want it.
 
in_array(haystack: $arr, needle: $search) <--- What 99% of people asking for named parameters actually want.
6
 
@Sara I send the send the object to a web service, the fomat of the request should be without keys
 
@Boytun But that format doesn't make sense. Objects have keys.
 
Wes
3:14 PM
i suspect a lot of people don't like a lot of small almost trivial files. they will do anything to avoid creating a new file and put a small class in it
 
You're describing something that no data interchange actually uses.
 
@Sara I think Boytun means, they want a plain array of values...
 
@Danack I suggested array. He specifically said he needs an object without keys.
 
@Sara I know, but the web service want work within the keys
 
Wes
except exceptions, they always go to town with exceptions. this relatively simple code i am working on right now has easily over 30 exception types :B
 
3:16 PM
@Boytun No. You're not hearing me. You cannot possibly be interpreting the webservice's API correctly. Unless it's just a phenomenally bad API. But I'm inclined to assume PEBCAK
 
@Boytun It looks like you should foreach over the data, and create a new array/structure with the data how you want it.
 
Do you have a link to its documentation?
 
@Sara dat leading B....
 
@Danack "B"rokenness? :)
 
Broblem.
 
3:18 PM
@OndřejMirtes Yeah, there might be some slightly overzealous restrictions right now when it comes to named params + unpacking
 
Wes
@bwoebi i don't like it, at all. i rather create a "subpackage" or a "subnamespace" and put a class in there
 
@NikiC Alright, I'll include it in PHPStan :)
 
@Wes That's nice. Don't use them then. Other people very much like them.
But you've made clear you don't like them. People aren't going to spend energy trying to change your mind.
 
@OndřejMirtes We'll probably want to lift some restrictions in PHP 8.1
 
@Sara this how I create the object:
 
Wes
3:20 PM
@Danack we'll see :P i was responding to the fact that "default" might still be an option
 
@Boytun Okay.... but how about that API documentation link?
 
Sorry, the api is secret, sorry
 
Well, good luck then.
 
and it is very sepecific
 
1 message moved to Trash can
9 mins ago, by Danack
@Boytun i) Please use something like https://gist.github.com/ to avoid posting walls of text ii) It looks like you should foreach over the code, and create a new array/structure with the data how you want it.
This is a problem where you need to write some code, and unfortunately for you, this room is not a code writing service.
 
3:23 PM
It's not even that. He wants an object without keys. Those don't exist in any language.
So he's misunderstanding his API and can't provide us with enough context to show him how he's misunderstanding it. What he needs isn't code, it's comprehension.
 
Writing the code will give him something to do while he learns to understand the context...
 
@Danack How do you move individual posts to Trash Can? I can kick users, so I'm pretty sure I have mod privs, but I can't find the button to junk an individual comment.
 
Look at this line: $request->createRequest->Lines->$key = $newLine; if we can push $newline into Lines without using $key... we win
 
And if horses were apples they'd ferment. What's your point?
 
$newLine is an object, that can repeat many time into Lines
 
3:28 PM
@Sara click room at top right, click move messages, get confused by the instructions, then click carefully.
@Boytun hi - no. We're not going to help you. You need to go and write some code.
 
@Danack hah. wow. that's staggeringly weird UI.
 
Try bookmarking a conversation next...
 
Let me try reframing this for you.
You have $200 in your bank account, and you want to buy something that costs $500.
You tell the store clerk, "How can I buy this thing with $200?"
The clerk responds, "You can't. It costs $500."
You insist, "Yes, but I only have $200, you should give it to me."
You want something to happen that simply isn't going to.
Unless maybe you then add: "Surely there's....something I could do...." ((soft music begins playing)) "Some way I could pay you..."
But that's not going to work here.
 
I think that this is a community for php developers, wich everyone can help each other
 
If you'd like to understand *WHY* what you're asking is impossible, have a read of: https://en.wikipedia.org/wiki/Associative_array
Note that objects are a form of dictionary (aka associative array), so everything that applies to dictionaries applies to objects.
@Boytun It is, but nobody can help you do something that can't be done.
 
3:45 PM
For the record, the purpose of this room (imosho) isn't to help people, it's to facilitate useful conversations.
 
"Support group for those afflicted with PHP." That can be read oh-so-many ways, man. :D
 
"I'm Crell, and I use PHP."
 
HI CRELL
 
I have been using PHP for 10 years. It started with PHP 5, but then I moved to stronger stuff: PHP 7. Now, I even occasionally do C
 
@Dharman wait until you try 8, the rush it gives, woah
 
3:58 PM
@Sara you're forgetting about....
 
4:12 PM
When I started with PHP, v3 was the new shiny.

... Yes, I'm old.
 
@StatikStasis It is. Today I have come to Scotland without a coat.
 
@Wes named parameters are applicable to more situations than parameter skipping; for instance, changing the order of parameters
which is applicable even if the function takes only two parameters (cough needle, haystack cough)
 
Named params, attributes, and constructor promotion are the defining features of v8. They're game changers.
 
there are definitely cases where skipping parameters would lead to tidier code; but there are also cases where named parameters are significantly more readable, e.g.: $foo->bar(true, default, default, false, default, true) vs $foo->bar(active: true, disposable: false, magic: true)
or to use a real-world example, $amqpChannel->queue_declare(default, default, default, default, default, true) vs $amqpChannel->queue_declare(nowait: true)
 
@DaveRandom how cold are you?
 
4:30 PM
@Crell just stumbled on your musings about ::class with enums; it's important to remember that in the general case, ::class doesn't actually know anything about the thing on its left-hand-side, it's pure string-manipulation
you can write namespace Foo { echo Nonsense::class; } and it will echo Foo\Nonsense, even though you didn't define anything
as of 8.0, there's a $foo::class case which does have an actual object on its left, so I guess that needs to do something
 
@IMSoP Although in our case Clubs::Hearts::class would actually be on a value (which is supported since PHP 8).
So this will actually happen at runtime.
 
do you mean it would be equivalent to $foo=Clubs::Hearts; $foo::class; ?
 
@IMSoP Yeah exactly. The engine will just handle Clubs::Hearts like any other constant lookup.
Now that you mention it, I wonder if that even works, grammar wise, or if it will require parens.
 
yeah... but if the parser can handle it, I guess it's just a case of defining a meaningful answer to get_class(Clubs::Hearts)
it would certainly be clearer what's happening as (Clubs::Hearts)::class; the multiple ::s looks weird
 
@IMSoP Yeah agreed. The grammar does seem to work. 3v4l.org/6Q8Ko
 
4:41 PM
ah, nice
 
5:10 PM
"What Iliya said". :-)
 
5:21 PM
@Crell Who's that? :P
 
Sorry, Ilija. (You and your Croatian spelling...)
 
Wes
5:31 PM
@IMSoP right, though personally i'd use classes for that
what would be great is to have arguments actually based on a struct data structure
and allow both.
that is what i'd loved to have
1 message moved to Trash can
so basically that would be named arguments only on constructors.... ?
i didn't even think about it. interesting. i like that :P
 
Why does this produce such a strange output? 3v4l.org/8hUc0
 
Wes
5:49 PM
@Dharman < should be &lt;
 
@Dharman Never, ever use strip_tags
Does that answer your question?
 
So far strip_tags has been working well for me.
@Wes Why should it be &lt; if it is not even an HTML tag. Isn't the purpose of that function to identify tags and remove them? Other wise I could find the first < and last > and remove everything between them
 
Wes
it's not valid sgml/xml
< iirc now is allowed in attributes, like <bar foo="bar<baz"> but otherwise should be always &lt; unless it is a tag
 
Ok, so that means that I need to reverse the sequence with htmlspecialchars_decode. First strip and then decode, which in hindsight makes sense
 
6:12 PM
@Wes yep, that's basically valid in PHP 8; add constructor promotion, and you get this: 3v4l.org/2qafu
which is what I've always thought: structs don't replace named parameters, because you still need a syntax to initialise those structs (with appropriate defaults)
to take my previous example, the nicest I can picture in PHP 7 would be $amqpChannel->queue_declare(QueueDeclareParams::default()->withNowait(true))
which is ... bleugh
with named params, you can either $amqpChannel->queue_declare(nowait: true) or $amqpChannel->queue_declare(new QueueDeclareParams(nowait: true))
even if you only ever used them on "constructors", you might want to include static "factory" methods in that, since PHP has no named constructors
SelectionSpec::createNumeric(min: 20, max: 100), SelectionSpec::createSmart(pattern: '/foo/', caseSensitive: false), ...
@Dharman for anything but the most trivial HTML, you're probably better off using something that can parse the structure, like github.com/tgalopin/html-sanitizer which uses github.com/Masterminds/html5-php
 
I was just thinking, what if we could have <?phps instead of <?php declare(strict_types = 1); ?
 
@mega6382 my gut reaction is "no", because that further embeds the incorrect idea that "strict_types" is some generic "be stricter and betterer" switch
 
@IMSoP Yeah, but that seems like overkill for my use case. I can just use REGEX to remove all tags...
Sure, you can't parse HTML with regex, but you can remove HTML with regex
 
The optimal solution would be to have declare(strict_types = 1); by default, so there would be no need to make such declarations.
 
@Dharman like I say, depends on your source and your aim; if it's security-related and complete untrusted, strip_tags could be risky
@mega6382 again, no, for the reasons I wrote on the mailing list a few days ago
 
6:25 PM
It has nothing to do with security. I don't even know how I could possibly use strip_tags for anything security-related
 
@Dharman that's good then; believe me, people will use anything with "strip" or "escape" in its name as an attempt to sanitise user input
 
Why would I ever need to sanitize the input ;P
 
because you don't want garbage in your database?
:P
 
@IMSoP you can just reject that rather than sanitizing it :P
@IMSoP can you give the title for that email or a link to externals?
 
basically, strict_types=1 has no more right to be the default than strict_types=0
I like George's suggestion there of making the 0 mode stricter in the edge cases, which is what most people care about
 
cmb
6:29 PM
@IMSoP FILTER_SANITIZE_STRING is supposed to sanitize a string by stripping tags :p
 
@IMSoP Glad you appreciate it :p
 
@cmb ugh yuck
Why is that filter there, and why is it even named like that?
 
cmb
maybe someone felt that the filter API wasn't borked enough already ;)
 
@Girgias yes, I meant to say so on list, but couldn't think of anything clever to say :)
 
I started working on the float to int thing but it's currently laying as a branch on my local fork lol
 
6:34 PM
@IMSoP thanks, I read it a little bit and will read through the entire thread now, but yeah your point makes sense.
 
@cmb not to be confused with FILTER_VALIDATE_STRING, which doesn't exist, but was nonetheless used all over my company's code base...
 
@IMSoP Is this from your company? stackoverflow.com/questions/37931768/…
 
lol
"find the coder and beat them." :D
 
 
1 hour later…
Wes
8:04 PM
@IMSoP i didn't think about that. it's very nice with "struct" constructors
dang gotta try again to get php 8 xdebug and phpstorm working
 
@cmb I can't think of any sensible place to put links to it, apart from 'every page'. Managing exact links from an appropriate page in the PHP manual to an appropriate page on phpimagick isn't something I want to manage. Do you think anyone would object if I added a link on every page to the phpimagick home page?
something like 'more info & examples available at phpimagick.com'
 
9:06 PM
youtube.com/watch?v=2oGOuxcWx28 (Richard Cheese & Lounge Against The Machine - Smoke Two Joints)
I mean that whole album tho
 
cmb
10:00 PM
@Danack well, what about adding a few words about phpimagick.com on php.net/manual/en/imagick.examples.php (and maybe a list with direct link to the categories)?
 
Wes
10:13 PM
class A{}

class B extends A{
   public function __construct(A $parent){
        $this->top = $parent;
   }
}
actual code i am working on has this structure
how do you feel about that :B
to be fair, it's not too bad
 
sounds like a linked list or a tree
 
Looks like a proxy pattern to me. /shrug
I mean, not so much the use of the word "top", but otherwise.
 
Wes
it is super messy because they use both e.g. parent::foo() and $this->top->foo()
can't figure it out yet
i mean, it's not a parent child structure, B delegates both to parent:: and $this->top
 
B represents two of A essentially?
 
Wes
the code is actually not much but i am dumb and i can't figure it out :B
 
10:25 PM
@Wes ... why?
 
Wes
i don't know
it's like a fallback implementation
this person is clearly more intelligent than me, so maybe there's a good reason for this
 
11:18 PM
Is anyone else working on attributes documentation yet?
Or constructor promotion?
 
@Crell Attributes I think @beberlei but constructor promotion and match has no one doing them yet
 
Cool. Promotion sounds simple enough to do tonight. I'll give it a shot.
If I can figure out where it would make the most sense. :-)
 
In the OOP section I'd imagine
 
Which is still oop5. shrug.gif
 
Well yes but Tiff send an email to look at changing that (cause I CBA to do it)
 
11:23 PM
I saw. I support this.
Ha. Old-style constructors are still described in here. Should that be removed?
 
No, as we still need to document PHP 7
And they are only deprecated in PHP 7
 
I thought they were removed?
 
But you could reword the section and all
They were removed in PHP 8, or am I miss remembering my timeline
 
I recall them causing problems to still use as far back as 5.3...
 
Still work in PHP 7: 3v4l.org/o10co
 
11:29 PM
Hm, but do nothing in 8.0.
OK, I'll try to clean that up while I'm in here.
 
Well, they aren't a constructor anymore. They're still there, of course.
 
:)
 
The notes on this page seem contradictory... Or at least in need of a serious update.
 
You can also drop the PHP 5 mentions and info only relevant to PHP 5
 
Da.
Holy crap there's a lot of ancient comments here talking about the lack of multiple constructors. :-)
 
11:32 PM
@Crell Well according to the docs it's only classes in the global namespace which have the fallback constructor behaviour? so ... yeah that's confusing
 
Oh that's even worse...
For docs purposes, nothing before PHP 7.0.0 needs to be mentioned at all, yes?
 
@Girgias argh, going to have to make time this week or maybe during Thanksgiving break next week and look at this
Going to check out one of the translated doc repos and try what Andre said to see what it looks like
 
@Crell Indeed if it has been removed in 7.0.0, or is true in 7.0.0 then it doesn't need to be mentioned or have a version mention attached to it :)
 
Will also need to look at what you said, @Girgias
(making mental notes)
 
Well there are a lot of docs to check through lol
 
11:46 PM
I'm having a naming problem. I have a function that compares two strings and returns the offset at which they compare not equal. Except, if they aren't equal it may give an offset less than the one at which they are not equal (but never equal to or greater). The fuzzy bit at the end is because I'm using tricks to compare multiple bytes at a time, and don't really care exactly which byte is neq because most of the time I just use it as a building block for seeing if two strings are equal.
Since most of the time I don't care exactly which byte it is, I can save a bit of work by not giving an exact match. Anyway, what should I name this thing?
 
So foo("ballgag", "balloon") would return 4? You're looking for a name for foo?
 
Yes, but it would be permitted to return anything less than 4 as well.
 
first_diff_index?
str_diff_index?
str_diverge_index?
 
Well, at least when 9.x goes live, we won't have to worry about removing mentions of 6.x :P
 
hehehe
Do we ever use sect3?
 
11:57 PM
Yes
 
Cool, then I will. :-)
 
moo
 
squeak!
 

« first day (3684 days earlier)      last day (1250 days later) »