No arguments provided php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Arguments Given #163

No Arguments Given #163

Comments

 require_once(dirname(__FILE__)."/../../vendor/autoload.php"); require_once(dirname(__FILE__)."/inc/Foo.inc"); class Test < private $Foo = null; function __construct(Foo $Foo) < return $this->Foo = $Foo; > > $test = new Test();
class Foo < function __construct() < echo "I'm made!"; > >

Catchable fatal error: Argument 1 passed to Test::__construct() must be an instance of Foo, none given, called in ../test.php on line 16 and defined in ../test.php on line 10

The text was updated successfully, but these errors were encountered:

In your first example you are not using the container at all. And even in the second one.

PHP-DI can’t automagically do something when you do a new , you have to get objects from it to benefit from dependency injection:

Your documentation is a bit misleading, and I don’t think it has enough working code examples (if any). The Getting Started guide also fails to mention the need to include the autoload.php file.

It does imply a bit that nothing else needs to be done:

«PHP-DI will know that it should inject an instance of the Bar interface or class.
No configuration needed!»

That’s why I thought it was automagical.

The code snippets are also a bit out of context and difficult to figure out how to use. For example, you’re telling me to use:

But where do I get the $container object from? That code wouldn’t run. And then in subsequent sentences, you say not to even use that method. The Getting Started guide says to use the code above, but then in the Best Practices guide, it’s contradictory:

«1. never get an entry from the container directly (always use dependency injection)»

So what does that even mean? If I’m not supposed to get objects from the container directly, what am I supposed to do? The docs say to do something and then say not to do it.

Your docs also say to do this:

$builder = new ContainerBuilder();

Do you realize that this code doesn’t run unless namespaced? Fatal error: Class ‘ContainerBuilder’ not found .

$builder = new \DI\ContainerBuilder();

I think you mention this somewhere in your docs, but there are still places that demonstrate the incorrect way that throws a class not found error.

Your website looks great, but there is too much conflicting and unclear (and incorrect) information on how to actually get PHP-DI working. I can’t find any working code samples either. I really don’t understand how you’re intending for this to be used, which is a shame, because it makes some great claims. The Getting Started guide doesn’t actually contain enough code or steps to get someone properly started. You obviously went through all of the trouble to write this framework, so I don’t understand why the docs would be so disjointed and riddled with conflicting information and why there aren’t solid code examples to get things working.

Thanks for the detailed feedback.

Yes you are right, all the documentation and examples take some stuff for granted:

  • you are using composer
  • you know namespaces and expect any code to be namespaced
  • you know what dependency injection is
  • you know what is a dependency injection container
  • you know roughly how you will use it

That’s many of assumptions, and if you fail any one of them, then it’s not really straightforward unfortunately.

I didn’t write a more «start from scratch» documentation because it takes a lot of time.

I don’t expect this library to be picked up like anyone would pick a new framework to try and learn it. I rather consider it the container you end up using after learning with simpler ones, or your own, and realizing that’s a lot of work to write a good one and the simpler ones miss critical features.

I have nothing against changing that though, preaching the word of dependency injection and (correctly used) containers is great. I just didn’t take to do it yet. If you (or anyone reading this) wants to get working on the docs to make an easier to grasp «getting started», I’ll be pleased.

Now that’s why the documentation is like that. It’s targeting developers that know what they are looking for, and that know how they want to architecture their application. I hope that doesn’t sound pedantic, because that’s really not how I intend it. I really hope some day to write a very good quickstart on how to build a good application using a container, but that’s a lot of work 🙁

But to answer some of your questions:

The Getting Started guide also fails to mention the need to include the autoload.php file

If you use composer, it should be straightforward.

But where do I get the $container object from?

From wherever you want to. You create it, so keep it where you want. In most applications, it’s usually created in the bootstrap of the application and used by the front controller to create controllers (when doing the routing). (FYI the front controller is usually the index.php file)

And then in subsequent sentences, you say not to even use that method.

Yes. Using the container directly is bad because it’s the service locator anti-pattern. You should only use the container at the root of your application, i.e. the front controller (e.g. index.php ).

Do you realize that this code doesn’t run unless namespaced?

Yes it was implicit, but it might be confusing so OK I’ll change the doc when I get the occasion (or if you want send a pull request).

Have a look at this link too: http://php-di.org/doc/understanding-di.html maybe it will help a bit.

I also suggest you to have a look at Pimple, another container that is much simpler (but obviously with less features). Maybe it will also help you get how containers are supposed to be used.

I hope it helps. If you want to keep using PHP-DI let me know the troubles you have in here and I’ll try to help.

Источник

Contact form — No arguments provided

Questions : Contact form — No arguments provided

I am trying to use the below contact form solved ourcodings html but I am getting a ‘No arguments provided solved ourcodings html error, can anyone take a look at my code to solved ourcodings html see I have gone wrong.

 
Submit -->
$name = strip_tags(htmlspecialchars($_POST['name'])); $email_address = strip_tags(htmlspecialchars($_POST['email'])); $phone = strip_tags(htmlspecialchars($_POST['phone'])); $message = strip_tags(htmlspecialchars($_POST['message'])); // Create the email and send the message $to = 'nigel.smith@nswd.co.uk'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to. $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message"; $headers = "From: nigel.smith@nswd.co.uk\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com. $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true; ?>

Answers 1 : of Contact form — No arguments provided

Input name is case sensitive, and there solved ourcodings html is a whitespace on Phone and Message solved ourcodings html name

Источник

No arguments provided php

To experiment on performance of pass-by-reference and pass-by-value, I used this script. Conclusions are below.

#!/usr/bin/php
function sum ( $array , $max ) < //For Reference, use: "&$array"
$sum = 0 ;
for ( $i = 0 ; $i < 2 ; $i ++)#$array[$i]++; //Uncomment this line to modify the array within the function.
$sum += $array [ $i ];
>
return ( $sum );
>

$max = 1E7 //10 M data points.
$data = range ( 0 , $max , 1 );

$start = microtime ( true );
for ( $x = 0 ; $x < 100 ; $x ++)$sum = sum ( $data , $max );
>
$end = microtime ( true );
echo «Time: » .( $end — $start ). » s\n» ;

/* Run times:
# PASS BY MODIFIED? Time
— ——- ——— —-
1 value no 56 us
2 reference no 58 us

3 valuue yes 129 s
4 reference yes 66 us

1. PHP is already smart about zero-copy / copy-on-write. A function call does NOT copy the data unless it needs to; the data is
only copied on write. That’s why #1 and #2 take similar times, whereas #3 takes 2 million times longer than #4.
[You never need to use &$array to ask the compiler to do a zero-copy optimisation; it can work that out for itself.]

2. You do use &$array to tell the compiler «it is OK for the function to over-write my argument in place, I don’t need the original
any more.» This can make a huge difference to performance when we have large amounts of memory to copy.
(This is the only way it is done in C, arrays are always passed as pointers)

3. The other use of & is as a way to specify where data should be *returned*. (e.g. as used by exec() ).
(This is a C-like way of passing pointers for outputs, whereas PHP functions normally return complex types, or multiple answers
in an array)

5. Sometimes, pass by reference could be at the choice of the caller, NOT the function definitition. PHP doesn’t allow it, but it
would be meaningful for the caller to decide to pass data in as a reference. i.e. «I’m done with the variable, it’s OK to stomp
on it in memory».
*/
?>

Источник

Читайте также:  List has index python
Оцените статью