Problems with string type constraints

Source: Internet
Author: User
function foo (string $s) {   echo $s;} Foo ("Hello World");

Error catchable fatal error:argument 1 passed to Foo () must is an instance of string, string given, called in
Why is this? How should I write it?


Reply to discussion (solution)

Type constraints are actually a setback

Type constraints only support objects and arrays of two types. Integer and string types are not supported.

PHP is weak type is not supported for simple types, generally supports object and array

PHP function declaration parameter does not need to specify type

settings.php

False

addressmanager.php
Class addressmanager{
Private $addresses = Array ("209.131.36.159", "74.125.19.106");

function Outputaddresses ($resolve) {
foreach ($this->addresses as $address) {
if (!is_bool ($resolve)) {
Die ("outputadresses () requires a Boolean argument\n");
}
Print "
";
}
}
}
$settings = simplexml_load_file ("settings.xml");
$manager = new Addressmanager ();
$manager->outputaddresses (String) $settings->resolvedomains);
But here $manager->outputaddresses ((string) $settings->resolvedomains), the type constraint is yes

Well, it's very
Thank you

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.