Jump to content

What does "with" imply


NotionCommotion

Recommended Posts

Often, I see "get" and "set" used in a function name, and the intent is obvious.  Other times I see "with" (i.e. PSR-7's withScheme, withUserInfo, withHost, withPort, withPath, withQuery, withFragment).  It appears to indicate just to clone itself ($this), apply the argument, and return the new object.  Am I correct?  Thanks

  • Like 1
Link to comment
Share on other sites

Yes, I recognize that "with" isn't a programming term.  I've seen it used elsewhere and not just by psr7, and expect that other specifications and frameworks/libraries/etc will use the English definition of the word the same way.  In my original post, I stated that I believe it to indicate that a cloned copy of an object will be returned but with a single changed property value, and I am now almost certain this is correct.  Is it common for other frameworks to use this same definition?

 

Quote

 

Definition of with 

1a: in opposition to : AGAINSThad a fight with his brother

b: so as to be separated or detached frombroke with her family

2aused as a function word to indicate a participant in an action, transaction, or arrangementworks with his fathera talk with a friendgot into an accident with the car

bused as a function word to indicate the object of attention, behavior, or feelingget tough with himangry with her

c: in respect to : so far as concernson friendly terms with all nations

dused to indicate the object of an adverbial expression of imperative forceoff with his head

e: OVER, ONno longer has any influence with them

f: in the performance, operation, or use ofthe trouble with this machine

3aused as a function word to indicate the object of a statement of comparison or equalitya dress identical with her hostess's

bused as a function word to express agreement or sympathymust conclude, with you, that the painting is a forgery

c: on the side of : FORif he's for lower taxes, I'm with him

d: as well ascan pitch with the best of them

4aused as a function word to indicate combination, accompaniment, presence, or additionheat milk with honeywent there with herhis money, with his wife's, comes to a million

b: inclusive ofcosts $5 with the tax

5a: in the judgment or estimation ofstood well with her classmates

b: in or according to the experience or practice ofwith many of us, our ideas seem to fall by the wayside— W. J. Reilly

6aused as a function word to indicate the means, cause, agent, or instrumentalityhit him with a rockpale with angerthreatened with tuberculosishe amused the crowd with his antics

barchaic : by the direct act of

7aused as a function word to indicate manner of actionran with effortacknowledge your contribution with thanks

bused as a function word to indicate an attendant fact or circumstancestood there with his hat on

cused as a function word to indicate a result attendant on a specified actiongot off with a light sentence

8a(1): in possession of : HAVINGcame with good news

(2): in the possession or care ofleft the money with her mother

b: characterized or distinguished bya person with a sharp nose

9aused as a function word to indicate a close association in timewith the outbreak of war they went homemellows with time

b: in proportion tothe pressure varies with the depth

10a: in spite of : NOTWITHSTANDINGa really tip-top man, with all his wrongheadedness— H. J. Laski

b: except forfinds that, with one group of omissions and one important addition, they reflect that curriculum— Gilbert Highet

11: in the direction ofwith the windwith the grain

 

 

Link to comment
Share on other sites

And once again you are into something that most of us have never dealt with!  So what is it that a person like you is doing with this new-found mystery?  Or are you in fact simply a hunter of the off-beat and curious ephemera, set on sharing your discoveries with this PHP-related community?  Do you really have a need to use all these bits and pieces in your programming efforts?

  • Like 1
Link to comment
Share on other sites

13 hours ago, NotionCommotion said:

In my original post, I stated that I believe it to indicate that a cloned copy of an object will be returned but with a single changed property value, and I am now almost certain this is correct.

Yes.

13 hours ago, NotionCommotion said:

Is it common for other frameworks to use this same definition?

If they use the word "with" then the code tends to have a similar meaning. Or they may do similar code but not name it "with". In fact I'd say it's more common not to use "with" and instead to name the methods normally and then support method chaining.

Link to comment
Share on other sites

43 minutes ago, requinix said:

In fact I'd say it's more common not to use "with" and instead to name the methods normally and then support method chaining.

I tend to agree, but didn't want to oppose a better standard.  I think the reason they do so is they wish to enforce immutability (which I see value but am still undecided).

Link to comment
Share on other sites

The PSRs have to work in terms of interfaces which means all operations must be methods, so setting a URL scheme would need a method. To support chaining the method can return an instance of the class, but that doesn't imply it's immutable: there could very well be something like a Url class and an ImmutableUrl class, and they would both behave the same way. Immutability would be primarily stated through documentation - or a class name. It's also implied to a lesser extent through coding: if a Url::foo() method returns an instance of Url, calling code should assume that the return value could be a new instance.

Immutability is mostly a form of defensive programming, guaranteeing that an instance of an object in one place cannot be modified in another place. There are times when it is a technical requirement, mostly because underlying data can/should not be modified in place, but with high-level languages like PHP they're fairly rare.

Remember the PSRs are primarily for framework interoperability - so that they all use a similar (if not identical) implementation of a common concept, so they can mesh a little better with each other. They are not a PHP community standard. There's nothing saying you need to, or even should, abide by their decisions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.