« first day (3581 days earlier)      last day (1358 days later) » 

10:02 PM
@Earlee Check the domain of the requests
 
@MarkR I think @Danack made some ways that direction, but I don't remember the details.
 
@Girgias Doesn't the above function ignore all chars other than 0-9?
 
cmb
And even if the return value was negative, it would be converted to a positive (unsigned) value (the details are implementation defined; usually just interpreting the bit pattern as unsigned integer).
 
@NikiC Wait, a match rfc passed?
I do not remember this.
 
@LeviMorrison Yes and that was before the rush before FF for RFCs
 
10:10 PM
Urgh... am I going to hate it?
 
Probably not actually, it's a pretty decent addition
 
@gharlan Maybe better to just ask @Derick at this point, as it seems to do that indeed.
@LeviMorrison Nah, it's pretty neat and sane
Maybe more work for well your job to support :p
 
@Derick Am I correct that the intention of the first function is to support positive numbers only, and the intention of the second function to extend the first one by supporting also negative numbers?
 
Find me tomorrow, I'm off to bed.
 
OK 👍
 
cmb
10:17 PM
@NikiC ah, yeah, thanks for the reminder! :)
And yes, blockers during pre-release are bad, but I'm afraid everybody has to live with that. :(
 
Is defining an interface without any methods (for type hinting) a good idea?
 
Seems rather useless
 
I have Eloquent models, so the models extend the Eloquent model. I want to be able to typehint Model or something in other places in my app, but I don't want to tie other places to Eloquent. So I'm thinking I just have them all extend ModelInterface (which has no methods) just so I can typehint ModelInterface
I might be doing this all wrong haha
 
That's still not going to be helpful
 
Why not?
 
10:25 PM
I use methodless interfaces in place of what I will in future use certain attributes for
 
Because at that point you should just type hint the Eloquant model
 
I don't want to couple my services with Eloquent models though
 
The point of an interface is so that you can swap out implementations by having a common method
Yeah, but that won't help
 
I want to couple them with my models. Then the my models are coupled with Eloquent models
 
I don't know how Eloquant works
But I imagine there is a standard CRUD
So just make that your interface
And use a bridge implementing this interface which works with eloquant
Then if you change to Doctrine you just need to write another bridge implementing the same interface
 
10:27 PM
So if I want to change it I only have to change my models to not be coupled with Eloquent, instead of changing everywhere that the Eloquent model is type hinted
 
@Alesana With an empty interface you are still doing that IMHO
 
Right, I have a repository pattern to interact with the models and they're the only thing that interacts with the model
 
You're doing duck taping and it's rather useless
The point of an Interface is that you can call methods on it
 
@MarkR That would make sense too but that's just planning things out :p
@Girgias Hmm I suppose you're right. I'm just wondering how I type hint my models in a service without tying my service to the eloquent model
 
If you use an Interface as a Type and try to interacts with it your IDE should shut at you and a static analyser will definitely shout at you
 
10:29 PM
I have an EloquentRepository implementation of each RepositoryInterface, and a RepositoryInterface for each Model I have
 
Just have a "DataProvider" interface or whatever, and have another class implement that which translates the designated interface methods to the relevant ones for eloquant
 
So really I'm only interacting with the Repository, but if I want to pass the model from a service to another service (to be passed back into a Repository as needed), I want to be able to type hint that
 
If you need to change to doctrine you create a new class implementing DataProvider doing that for Doctrine
 
I think the Repository is the DataProvider
 
Again you're not abstracting it
 
10:31 PM
Right that's what I'm doing so as far as calling the methods I've got that covered
 
The point of an interface is to have a level of abstraction
 
I have UserRepositoryInterface

and Eloquent\UserRepository implements UserRepositoryInterface
 
That's irrelevant
I don't know Eloquent
 
Right but I would be able to easily switch that out with Doctrine is what I mean
 
IDK define 5 methods for the DataProvider:
get($id)
getAll()
update($id)
insert()
delete($id)
 
10:33 PM
Ah, that would solve the issue too. Right now I'm doing update(Model $model)
(which ties it to Eloquent)
 
And make a separate service class EloquentDataProvider which implements that interface and in it's constructor takes the Eloquent objects
And then that service class does the mapping between your interface and whatever names Eloquent uses
 
Right that's what I'm doing
 
Then if you change for Doctrine the only thing you need to change is to make a new DoctrineDataProvider and have your DI container handle the dependencies
 
But for the get($id) for example, I want to type hint the return type
 
So you want an abstract Entity?
 
10:35 PM
I don't know what I would type hint it to, because using any type hint would tie the interface it to the eloquent model
 
You shouldn't care about "model"
 
Yeah, but without any methods (because the EloquentDataProvider knows how to interact with Eloquent models)
What would I type hint the return type as then?
That's really the only thing I'm getting stuck with
 
A model is more or less just a data provider for what the controller wants
Well the problem is you would need generics to implement this nicely
 
interface DataProvider
{
    public function get(int $id): ???;
}
 
Or a typical collection type
Just use an object return type
You can't solve that without generics if I understand what you want to do
 
10:38 PM
good day everyone
 
Hmm I'll look into Generics
 
For that you need to use a static analyser as PHP doesn't have them (yet)
 
Oh damn. So I also want to use the same type hint in...
interface DataProvider
{
    public function update(array $attributes, ??? $model): ???;
}
So I can't pass in a random class that is an object
 
currently using array_search() to find the position of a key in an array but this times out on large array values, is there a shorter way to do this when am sure the key exists but just want the position thanks.
 
That's why I'm like, if I only let certain classes implement an empty ModelInterface, then I can use type hinting to safely assure that only those classes are allowed
 
10:40 PM
@Alesana You can use self or better, static in PHP 8.
@Sara Not sure, but I don't think you have any difficulty appearing smart Sara ^^
 
if you know what keys you looking for you could sort the array first.
 
@IluTov The Model isn't an implementation of the Repository (DataProvider) though
The Repository just is the only thing that interacts with the model
Maybe I should just refer to them only by ID
 
yes it is already sorted
 
@Alesana Oh sorry, I didn't read it well enough. You'd need associated types or something like that, so you can't type hint it unfortunately.
 
@IluTov So you don't think using an empty Interface would be a good workaround to associate all the Models with the same type?
(by implementing it in all the models)
 
10:44 PM
@Alesana Not really, you'll still be able to pass models to DataProviders that don't handle the given model type.
Probably better to just use @template and Psalm/PHPStan :)
 
you could also split it
 
Ah yeah, I'm fine with that though as long as I know it's a model
 
Hello everyone
 
I'll look into Psalm/PHPStan
 
@BobbyAxe That seems like a very odd requirement
 
10:46 PM
okay like split then search
 
yeah
 
I am trying to execute the below code:
<?php
// Your code here!
$a=2;
function b() { $a++; }
b();
?>
But its giving me error
I am new to php
Its saying undefined variable a
 
a major difference between php and other languages, is that scope does not inherit variables
 
@ILoveStackoverflow Compared to other programming languages variables are not imported from the parent scope
 
10:47 PM
So you need to use a "use()" clause
Or on PHP 7.4 a short lambda as that imports scope
 
Actually I am trying to figure out what is the value of a after b is called
 
and there are other less orthodox ways of doing this
 
/** @template TModel */
interface DataProvider
{
    /**
     * @var TModel $model
     * @return TModel
     */
    public function update(array $attributes, $model);
}

/** @template-implements DataProvider<User> */
class UserDataProvider implements DataProvider
{
    public function update(array $attributes, $model): User
    {
    }
}
 
@Girgias yeah i know but i was trying to find out why i got time outs all indications points to the array_search part of the code even tried using generators
 
function b(&a) by reference
 
10:49 PM
function b(int $a) { return ++$a; }
 
@Alesana Something like that. Unfortunately you still can't type-hint $model because of LSP
 
That's why I wanted to do an empty interface was a workaround for type hinting them while following LSP
 
@BobbyAxe Arrays aren't ideal, and if you know the key exists I don't understand why you need to know its position in the array
 
Can someone tell me what would be the value of a after b is called and what does this tell about variable scope?
 
may I ask you to reread the comment by Girgias after your question?
It answers as to why that code is not working, why it does not work with php.
 
10:51 PM
it says variable are not imported from the parent scope
but i didnt understood what it means
 
A function creates a new scope
 
@ILoveStackoverflow function is like a box that knows nothing about the outside.
so you have to pass variables by value or reference.
 
@Girgias wouldn't find my self in such a situation ideally but it unfortunately happens to be one of those annoying hacker rank questions something about Dense ranking
 
@Alesana Small demo: psalm.dev/r/95b2c9a310 (I meant to write @param not @var in the phpDoc)
 
but here we can say about the scope of variable $a that it has global scope right?
 
10:54 PM
the variable you declared is global. The variable inside the function is inside a box that knows nothing about the outside
 
@ILoveStackoverflow Again PHP does NOT import global variables into inner scopes
@BobbyAxe Probably the easiest/fastest is to use a foreach with a counter
Cause I don't have a better idea
 
<?php
$a=2; // $a is declared, exists in outer scope
function b() {
    $a++; // $a does NOT exist in inner scope
}
b();
 
there u
 
@Girgias here is a look at what i did pastebin.com/Fkss2PPS, don't know if it will make much sense as the question is not there
 
@IluTov Okay that makes sense. That's kinda what I would want to do but natively lol. I guess I wanted to use an empty interface as a template in a way
 
10:56 PM
foreach is faster
than array_search or doing anything else.
 
@ILoveStackoverflow 3v4l.org/lHSQ3 Not that globals are advisable.
 
alright let me try it out
 
@FélixGagnon-Grenier so that means there wont be change in value of $a right? value of $a will be 2 only
 
@Alesana Yeah you'll have to wait for generics for that ^^
 
function (&a) will change the value
 
10:57 PM
@BobbyAxe Yeah not familiar with that algorithm and the code doesn't make sense for my tired 1AM brain
 
lol i get
thanks anyway
 
@IluTov Makes sense
 
will give it a few more tries
 
In the meantime I might just do something like, instead of...
class User extends EloquentModel
{

}
I would do...
 
@ILoveStackoverflow yes, $a is both "local" to the function (in that case) and "global" to the outer execution context. as Sal says, if you want $a to be the actual same variable, you would change b() signature and pass the variable to the function call
 
10:59 PM
abstract class Model extends EloquentModel
{
}

class User extends Model
{
}
 
@Alesana Careful of all that inheritance. It can lead to unexpected complications.
 
@Crell Do you think this has more potential for complications than just having the user extend the EloquentModel itself?
 
@Alesana Yeah if anything please use interfaces, inheritance for stuff like that is not a great idea.
 
/me laughs in 10 layer deep inheritance controllers, true dat.
 
s/unexpected/expected
 
11:00 PM
@FélixGagnon-Grenier Great thanks. this apply to only core PHP only?
 
It has to extend the EloquentModel anyways
 
Yes.
 
this applies to all PHP code I can think of
 
Why do you want to have an intermediary inheritance level? What are you trying to get out of it?
 
I'm literally writing a JIRA task for a client, to kill all eloquent "models"
 
11:01 PM
Eloquent isn't. :-)
 
Yeh, gonna replace all with /** @psalm-immutable */ DTOs with public properties :)
 
@Alesana Did you hear back on your Datadog application at all?
 
I like me some thicc thicc models.
 
@LeviMorrison No I didn't
@Crell Just being able to type hint the models
 
If you just need a marker, use an interface.
 
11:07 PM
That's what my original question was, is it okay to use an empty interface there?
 
Absolutely.
 
Okay cool, yeah that would make things a lot cleaner
 
thumbsup.gif
 
That way I could type hint that interface in my services instead of the Eloquent model itself, and only my models would be tied to Eloquent (not the services)
 
This is a good thing.
 
11:09 PM
Thanks :)
 
Wes
sup folks
 
Sup wes o/
 
Wes
i updated phpstorm and wow it's bossy now
it's also wrong
 
11:24 PM
lol I thought that was antidote or something
 
Wes
it's called languagetool apparently
 
11:59 PM
function c(&$d) { $d *= 2; }
$e = 4;
c($e);
echo $e;// output 8
Here i am getting 8
 

« first day (3581 days earlier)      last day (1358 days later) »