How to instantiate class (from array) inside the loopDeleting an element from an array in PHPFatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)When to use static vs instantiated classesHow do I get a YouTube video thumbnail from the YouTube API?List of Big-O for PHP functionsHow to Sort Multi-dimensional Array by Value?Instantiating class by string using PHP 5.3 namespacesTraits vs. InterfacesReference - What does this error mean in PHP?Instantiate global class inside another class
How to drill holes in 3/8" thick steel plates?
How did the hit man miss?
Referring to different instances of the same character in time travel
Is Trump personally blocking people on Twitter?
Why did Harry Potter get a bedroom?
Why do people keep referring to Leia as Princess Leia, even after the destruction of Alderaan?
Is anyone advocating the promotion of homosexuality in UK schools?
Would dual wielding daggers be a viable choice for a covert bodyguard?
How to md5 a list of filepaths contained in a file?
Are randomly-generated passwords starting with "a" less secure?
Is "I do not want you to go nowhere" a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?
Managing and organizing the massively increased number of classes after switching to SOLID?
Do you know your 'KVZ's?
For a hashing function like MD5, how similar can two plaintext strings be and still generate the same hash?
How to loop for 3 times in bash script when docker push fails?
As the Dungeon Master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?
Why was hardware diversification an asset for the IBM PC ecosystem?
How can I effectively communicate to recruiters that a phone call is not possible?
Why do players in the past play much longer tournaments than today's top players?
How can a dictatorship government be beneficial to a dictator in a post-scarcity society?
What's the minimum number of sensors for a hobby GPS waypoint-following UAV?
Print the last, middle and first character of your code
Combining latex input and sed
C program to parse source code of another language
How to instantiate class (from array) inside the loop
Deleting an element from an array in PHPFatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)When to use static vs instantiated classesHow do I get a YouTube video thumbnail from the YouTube API?List of Big-O for PHP functionsHow to Sort Multi-dimensional Array by Value?Instantiating class by string using PHP 5.3 namespacesTraits vs. InterfacesReference - What does this error mean in PHP?Instantiate global class inside another class
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to instantiate class inside the loop, I've tried doing this:
<?php
use AppCaves_demographic_info;
use AppCaves_current_uses;
use AppCaves_flora_outside;
public function get_page4_contd_data($id)
$tables = [
'Caves_demographic_info', 'Caves_current_uses', 'Caves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
?>
It produces the error 'Class class_name not found', Is it possible to do that inside the loop?
php laravel
add a comment |
I want to instantiate class inside the loop, I've tried doing this:
<?php
use AppCaves_demographic_info;
use AppCaves_current_uses;
use AppCaves_flora_outside;
public function get_page4_contd_data($id)
$tables = [
'Caves_demographic_info', 'Caves_current_uses', 'Caves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
?>
It produces the error 'Class class_name not found', Is it possible to do that inside the loop?
php laravel
add a comment |
I want to instantiate class inside the loop, I've tried doing this:
<?php
use AppCaves_demographic_info;
use AppCaves_current_uses;
use AppCaves_flora_outside;
public function get_page4_contd_data($id)
$tables = [
'Caves_demographic_info', 'Caves_current_uses', 'Caves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
?>
It produces the error 'Class class_name not found', Is it possible to do that inside the loop?
php laravel
I want to instantiate class inside the loop, I've tried doing this:
<?php
use AppCaves_demographic_info;
use AppCaves_current_uses;
use AppCaves_flora_outside;
public function get_page4_contd_data($id)
$tables = [
'Caves_demographic_info', 'Caves_current_uses', 'Caves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
?>
It produces the error 'Class class_name not found', Is it possible to do that inside the loop?
php laravel
php laravel
asked Mar 26 at 2:22
JielJiel
3410 bronze badges
3410 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your approach seems right, can you try (with namespace)
$className = 'App' . $tables[$index];
$class = new $className;
So something like this in your example:
$tables = [
'AppCaves_demographic_info',
'AppCaves_current_uses',
'AppCaves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348961%2fhow-to-instantiate-class-from-array-inside-the-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your approach seems right, can you try (with namespace)
$className = 'App' . $tables[$index];
$class = new $className;
So something like this in your example:
$tables = [
'AppCaves_demographic_info',
'AppCaves_current_uses',
'AppCaves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
|
show 3 more comments
Your approach seems right, can you try (with namespace)
$className = 'App' . $tables[$index];
$class = new $className;
So something like this in your example:
$tables = [
'AppCaves_demographic_info',
'AppCaves_current_uses',
'AppCaves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
|
show 3 more comments
Your approach seems right, can you try (with namespace)
$className = 'App' . $tables[$index];
$class = new $className;
So something like this in your example:
$tables = [
'AppCaves_demographic_info',
'AppCaves_current_uses',
'AppCaves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
Your approach seems right, can you try (with namespace)
$className = 'App' . $tables[$index];
$class = new $className;
So something like this in your example:
$tables = [
'AppCaves_demographic_info',
'AppCaves_current_uses',
'AppCaves_flora_outside',
];
for($index = 0; $index < count($tables); $index++)
$$tables[$index]."_model" = new $tables[$index];
edited Mar 26 at 2:34
answered Mar 26 at 2:25
sentysenty
4,2758 gold badges60 silver badges142 bronze badges
4,2758 gold badges60 silver badges142 bronze badges
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
|
show 3 more comments
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
still not working.. second approach produces same error. first approach produces unexpected error
– Jiel
Mar 26 at 2:27
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
Can you try it with namespace? I just tried in my code, with full namespace it should work
– senty
Mar 26 at 2:30
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
how would you parse the backslash in the string though?
– Jiel
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
As it is works for me, did you get an error?
– senty
Mar 26 at 2:35
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
I've got it. It worked. Thanks!
– Jiel
Mar 26 at 2:37
|
show 3 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348961%2fhow-to-instantiate-class-from-array-inside-the-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown