PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] PHP "with" keyword - what does "with" do?

 January 08, 2022     laravel, php     No comments   

Issue

Can someone please explain what PHP "with" does?

Example begins:

Say I have a class:

\App\fa_batch

What is the difference between this statement:

$w = (with (new \App\fa_batch))
       // uses 'with'
       // returns App\fa_batch 

and this statement?

$n = (new \App\fa_batch)
       // does not use 'with'
       // also returns App\fa_batch 

Context / Background Info:

I'm having trouble finding documentation for with, maybe because the PHP.net, stack overflow and google search engines considers php "with" keyword such a common search phrase.

If context helps, I came across this usage of the word with from this answer: https://stackoverflow.com/a/33222754/5722034


Solution

with is not a keyword, it's a laravel function. The extra space between with and ( is a red herring.

The 5.2 docs include it in miscellaneous helpers. The source is available on github as well



Answered By - zzzzBov
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing