0

maybe its duplicate but i cant find it.

    something = new ArrayList<>(); 
something.add(new Object("Hello"));
something.add(new object("World"));
something.add(new Object("!"));
for(blablabla){
System.out.print(something.get(i).getTextFromConstructor());
}

this will print "Hello World!"

in php i dont know solution to pass whole objects into array to call their methods from loop or just by something[0]->method(); As i know this in php cannnot be done, but maybe i am wrong :-)

Thank You

2 Answers 2

1
$arr = array();
$arr[] = new MyUSerDefinedObject("Hello");
//...

echo $arr[0]->methd();
//or
foreach ($arr as $val) {
    echo $val->methd();
}
Sign up to request clarification or add additional context in comments.

3 Comments

lol it works? i tried it few years before but it does not worked. Thanks
ohh, with for it does not worked but with foreach yes.. thankyou
now i feel like begginer :D. Now i can write more object oriented php code
0

Use this example to set the bridge b/w php and java so that you can pass values to them

<?php
$date = new Java("java.util.Date", 70, 9, 4);
var_dump($date->toString());
$map = new Java("java.util.HashMap");
$map->put("title", "Java Bridge!");
$map->put("when", $date);
echo $map->get("when")->toString()."\n";
echo $map->get("title")."\n";

$array = array(1,2,3,4,5);
$map->put("stuff", $array);
var_dump($map->get("stuff"))."\n";

$system = new JavaClass("java.lang.System");
echo "OS: ".$system->getProperty("os.name")."\n";
$math = new JavaClass("java.lang.Math");
echo "PI: ".$math->PI."\n";
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.